In my MainActivity
, I first check to see if there is someone logged in. If there isn't, user is sent to LoginActivity
. If someone is logged in, I check to see if the token is valid, if not, again the user is sent to the LoginActivity
. If the token is valid, I then check to see if the user has completed the details on his/her profile. If they haven't, they are sent to the ProfileDetailsActivity
. If they have, the code should continue and the user should be at the MainActivity
. My issue is, when the user logs in, everything goes as it should. Since my test user hasn't completed the profile details, I am sent to the ProfileDetailsActivity
. BUT, if I close the application completely and I reopen it, the user stays at MainActivity
and is never sent to the profile details page. Here is my code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Backendless.initApp(this, BackendSettings.APPLICATION_ID, BackendSettings.SECRET_KEY, BackendSettings.VERSION);
String userToken = UserTokenStorageFactory.instance().getStorage().get();
showProgressDialog();
if (userToken == null || userToken.equals("") {
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
finish();
} else {
AsyncCallback<Boolean> isValidLoginCallback = new AsyncCallback<Boolean>() {
@Override
public void handleResponse(Boolean aBoolean) {
if (!aBoolean) {
Backendless.UserService.logout(new AsyncCallback<Void>() {
@Override
public void handleResponse(Void aVoid) {
Toast.makeText(MainActivity.this, BackendSettings.ERROR_SESSION_EXPIRED, Toast.LENGTH_SHORT).show();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
}
});
Intent intent = Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
finish();
} else {
BackendlessUser user = Backendless.UserService.CurrentUser();
if (user != null) {
boolean completeProfile = (boolean) user.getProperty("complete_profile");
if (!completeProfile) {
Intent intent = new Intent(MainActivity.this, ProfileDetailsActivity.class);
startActivity(intent);
finish();
}
}
}
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
}
};
Backendless.UserService.isValidLogin(isValidLoginCallback);
}
hideProgressDialog();
}
I have also tried moving this code block after hideProgressDialog
and still no good:
BackendlessUser user = BackendlessUser.UserService.CurrentUser();
if (user != null) {
boolean completeProfile = (boolean) user.getProperty("complete_profile");
if (!completeProfile) {
Intent intent = new Intent(MainActivity.this, ProfileDetailsActivity.class);
startActivity(intent);
finish();
}
}