Hello … When the user opens my app … it checks if there is user logged in or not … So I use that code to check:
if ( Backendless.UserService.CurrentUser() == null){
startActivity(new Intent(MainActivity.this, LogIn.class));
}
So when I login to the app … then close it and remove it from " the last opened app " in the emulator …then I reopen the app … current user returns null even if the user haven’t logout …and the Login Activity open why is that happen ? that mean CurrentUser method data will be deleted if I removed the app from “last opened app” ? Note : I mean remove the app from " last opened app " Not remove the app data from task manager or setting …And Thanks
The reason is that we cannot keep the whole user object - it may be too large, so we just keep his objectId. This means that you should retrieve the user by objectId when he opens the application (in case you had chosen to keep user logged in when logging in).
Here is an example from our code generation (by the way, you can download it for your app, too):
You receive BackendlessUser object in response to Backendless.UserService.findById( currentUserId, asyncCallback ). You can get any user’s property from BackendlessUser object using its getProperty() method.
and this is the code inside this method :
Backendless.UserService.isValidLogin(new AsyncCallback<Boolean>() { @Override
public void handleResponse(Boolean loggedIn) {
if(loggedIn && Backendless.UserService.CurrentUser() == null){
String CurrentUserId = Backendless.UserService.loggedInUser();
if(!CurrentUserId.equals("")){
Backendless.UserService.findById(CurrentUserId, new AsyncCallback<BackendlessUser>() { @Override
public void handleResponse(BackendlessUser curren User) {
Backendless.UserService.setCurrentUser(currentUser);
} @Override
public void handleFault(BackendlessFault backendlessFault) {}
});
}
}else{}
} @Override
public void handleFault(BackendlessFault backendlessFault) {}
}); then after i call this method …I check for current user and it’s returns null : userLoggedIn();
if ( Backendless.UserService.CurrentUser() == null){
}