User Session

Hi,

I was using Parse as backend for Android App development, now switched to Backendless.
In Parse, it used maintain User session automatically in the app. i.e If i signup with user, it used login in the app with same user credentials till I log out manually.
With Backendless, i coudn’t achieve that, please advise.

When a user logs in to Backendless, you can request that the login session becomes “persistent” by setting the stayLoggedIn argument in the login() API call to true.

Regards,
Mark

I’ll will explain in detail.

  1. I create a new user in the log
  2. User logged in and navigated to Home screen
  3. So as app is in development phase, we do changes to app (functional, not related to login) and build and run
  4. This time app should login automatically, as the user session not saved, redirects to login and screen
  5. I’ve login again as many times i build and run app.

What we are looking ( as it was in Parse): App should login user automatically once logged(or registered) till physically logs out of the app.

Thanks,
VIvek

If you set the stayLoggedIn parameter in the login API to true, then the login session is persisted and user does not need to login again.

Hi,

I have written following, still needs to login every time
Backendless.UserService.login(“username”,“password”,
new AsyncCallback<BackendlessUser>() {
@Override
public void handleFault(BackendlessFault arg0) {

						}


						@Override
						public void handleResponse(BackendlessUser user) {
						
						}
					}, true);

How do you check if the login is needed on the subsequent run of the app? Do you have code for that?

Using this below line of code to check UserID

String userId = UserIdStorageFactory.instance().getStorage().get();

Also trying to check Backendless.UserService.CurrentUser(), it returns null

Use this:

String userId = UserIdStorageFactory.instance().getStorage().get();

if userId is not null, then you can load the user object with:

Backendless.Data.of( BackendlessUser.class ).findById( userId, callback );

Inside of the callback you will get the user object and then you can set the current user with:

Backendless.UserService.setCurrentUser( user );

Regards,
Mark

Hi,

String userId = UserIdStorageFactory.instance().getStorage().get();

returns null

Could you copy/paste the login call from your code? What you posted earlier does not look right.

Hi,

Please point out the what is wrong with the code?

Backendless.UserService.login(“username”,“password”,
new AsyncCallback<BackendlessUser>() {
@Override
public void handleFault(BackendlessFault arg0) {

}

@Override
public void handleResponse(BackendlessUser user) {

}
}, true)

Hello!

Can you try the following case:

  1. Logout user calling logout() method
  2. Login with stayLoggedIn = true
  3. Shutdown the application
  4. Start application again and check user status
    Please notify me about your result.
    Thank you!
    Alex