Since I’m going to use often update calls on BackendlessUser instance I was wondering how and where to store mentioned instance, what would be the best practice? The aim is to retrieve the instance of the current user and store it for example in Application context and use it whenever I need to update some property in BackendlessUser object/table.
The method BackendlessUser.UserService.CurrentUser() doesn’t work (returns null value although the parameter stayLoggedIn in both Google+ and Facebook login calls is set to true) so I’m forced to use Backendless.UserService.findById() every time when I need to update some property in BackendlessUser object, which requires an additional call to the server.
BackendlessUser.UserService.CurrentUser() should work in your case, let me check it. I will notify you
Thanks Sergey,
Backendless.UserService.CurrentUser() does work when the user logs in for the first time through either loginWithGooglePlus or loginWithFacebookSdk but soon as I restart app the same method returns null value.
That is correct. After a restart, assuming you used persistent login, you can retrieve (and subsequently) set the current user object by doing the following:
String userId = UserIdStorageFactory.instance().getStorage().get();
Backendless.Data.of( BackendlessUser.class ).findById( userId, new AsyncCallback<BackendlessUser>()
{
@Override
public void handleResponse( BackendlessUser user )
{
Backendless.UserService.setCurrentUser( user );
}
@Override
public void handleFault( BackendlessFault fault )
{
// make sure to log any errors here.
}
});
for now there is no embed method to save BackendlessUser with backendless sdk. You can store all properties from BackendlessUser to shared preference, than retrieve it and set to new BackendlessUser.
I suppose we will add opportunity to store user and retrieve it in next month
Thanks guys! Mark’s answer did the trick since I’m using persistent login (I believe that means passing true as the last parameter of loginWithFacebookSdk and loginWithGooglePlusSdk method, correct me if I’m wrong).
I suppose we will add opportunity to store user and retrieve it in next month
Great, I’m looking forward for this feature!
Regards
String userId = UserIdStorageFactory.instance().getStorage().get();
this is not working in version 7.0.7 android. “cannot resolve symbol”