Stay logged in and retrieve user data

Hi.

I am trying to use the "stay logged in " functionality with Android SDK. It is working, the token has been saved in UserTokenStorageFactory, but i don´t know how to “reload” the logged in user, so i can have all its properties again, using the saved token. ¿Is it possible?

Regards,
Andrés

Hi Andres,

Yes, this is possible. Here’s what you can do to reload the logged in user:

String currentUserObjectId = Backendless.UserService.loggedInUser();
Backendless.UserService.findById( currentUserObjectId, asyncCallback );

once the response handler method is triggered in asyncCallback, then set the current user object with:

Backendless.UserService.setCurrentUser( currentUser );

Hope this helps.

Mark

Thanks Mark.

I was checking Android SDK in Github and i found UseIdStorageFactory class. The currentUserObjectId can also be obtained with UserIdStorageFactory.instance().getStorage().get()?

Regards,
Andrés

[reply user_id=149][h4]Andrés wrote:[/h4]Thanks Mark.

I was checking Android SDK in Github and i found UseIdStorageFactory class. The currentUserObjectId can also be obtained with UserIdStorageFactory.instance().getStorage().get()?

Regards,
Andrés[/reply]Yes, you can use this way, too. Moreover, this is how Backendless.UserService.loggedInUser() method is implemented. But the way Mark Piller suggested is more preferable, as it is more readable, obvious and short.

Ok, i will use what Mark suggested.

Thanks Sergey.

Regards,
Andrés