Answer the question
In order to leave comments, you need to log in
How to save the user on the device after a successful login to the application?
I have a simple registration form in the android application, but the problem is that every time I have to enter my login and password in order to use all the functions, so I decided to somehow save the user on the device. I save the sharedpreferences refresh_token and then I try to check at the start of the application whether there is already a saved token, if there is, then we move on through the application, and if not, then we log in, here is my code:
if (!(refresh_pref == null)) {
Intent intent = new Intent(LoginActivity.this, SecondScreen.class);
startActivity(intent);
} else {
try {
submitBtn = findViewById(R.id.btn_submit);
submitBtn.setBackground(getDrawable(R.drawable.button));
submitBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendPost();
}
});
} catch (Exception e) {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
SendLogcatMail(thread, ex);
}
});
}
}
Answer the question
In order to leave comments, you need to log in
how clumsily the logic is made. it’s better to make a separate splash activity in which you check if the user is authorized (is there something in preferences) and if so, open the main activity, and if not, then activate for authorization
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question