Backendless.UserService.isValidLogin() returns false every time

Hey guys,
I have a login issue.

  1. logging in with facebook,
  2. closing the app
  3. coming back to the app - the app goes to the login screen becuase
    Backendless.UserService.isValidLogin() returns false.

Thanks

Do you set the “stayLoggedIn” argument to true?

where can I set this argument?

Hi Tal,

Use overloaded method Backendless.UserService#loginWithFacebookSdk which takes forth parameter boolean “stayLoggedIn”.
Btw if you use IntelliJ Idea or Android Studio you can use key combination Ctrl+P to watch all overloads of method and which parameters they take.

Artur.

The stayLoggedIn parameter exists only in loginWithFacebook,
not loginWithFacebookSDK (what’s the difference?), or register

It sure is a part of loginWithFacebookSDK:

I see that in the source you sent (though register() does not have that argument).

I am using ‘com.backendless:backendless:3.0.8.1’ through gradle.

and not seeing those arguments. see attached print screen

Upgrade to 3.8.0.2

OK,

now I see this argument, but:

  1. the argument is missing from register() method
  2. I get an exception.
    I logged in with facebook sdk, then when I reopened the app, I got an exception in the line:
    if (Backendless.UserService.isValidLogin()) {(running inside onCreate())

Caused by: BackendlessException{ code: ‘Internal client exception’, message: ‘null’ }
at com.backendless.Invoker$SyncResponder.errorHandler(Invoker.java:127)
at com.backendless.core.responder.AdaptingResponder.errorHandler(AdaptingResponder.java:93)
at weborb.client.ioEngine.HttpIOEngine.send(HttpIOEngine.java:213)
at weborb.client.ioEngine.HttpIOEngine.invoke(HttpIOEngine.java:145)
at weborb.client.WeborbClient.invoke(WeborbClient.java:138)
at com.backendless.Invoker.invokeSync(Invoker.java:100)
at com.backendless.Invoker.invokeSync(Invoker.java:112)
at com.backendless.UserService.isValidLogin(UserService.java:787)
at com.taldroid.apps.tapextreme.login.WelcomeActivity.onCreate(WelcomeActivity.java:34)

The stayLoggedIn parameter doesn’t make sense in register method, as it doesn’t do login at all.

Due to an exception, in Android you should use an async version of this method: https://github.com/Backendless/Android-SDK/blob/master/src/com/backendless/UserService.java#L799

cool, the async works.

about register, it doesn’t do login? are you sure?
that means that I need to call register(), wait for the response, then call login(), wait for the response, and only then move to the next activity…

about register, it doesn't do login? are you sure?

Yes, 200% positive…

that means that I need to call register(), wait for the response, then call login(), wait for the response, and only then move to the next activity..

if the use-case in your app requires to login in the user after he/she registers, that’s what you should do then. Keep in mind that in some apps that require email confirmation, a user cannot login right away until they confirm their email address.

ok. I understand the flow now,
thanks

I’m getting the same issue and can’t seem to resolve it. Can you help me understand the async version of the method a little better. Or perhaps help me with how the “stayLoggedIn” syntax is written?

Here is what I’m currently doing.

To login the user I’m using the following code:

Backendless.UserService.loginWithFacebookSdk( LoginActivity.this, facebookFieldsMappings, permissions, callbackManager, new AsyncCallback<BackendlessUser>() 
{ 
 @Override 
 public void handleResponse( BackendlessUser backendlessUser ) 
 { 
 Toast toast = Toast.makeText( LoginActivity.this, "Ok, User ID ="+backendlessUser.getUserId(), Toast.LENGTH_LONG ); 
 toast.show(); 
 } 
 
 @Override 
 public void handleFault( BackendlessFault backendlessFault ) 
 { 
 Toast toast = Toast.makeText( LoginActivity.this, backendlessFault.toString(), Toast.LENGTH_LONG ); 
 toast.show(); 
 } 
} );


When the user closes the app and then starts it up again, I’m checking to see if they are already logged in with the following:

Backendless.UserService.isValidLogin(new AsyncCallback<Boolean>() { 
 
 @Override 
 public void handleResponse(Boolean response) { 
 
 if (response) { 
 
 Toast.makeText(SplashActivity.this, "Logged In", Toast.LENGTH_LONG).show(); 
 
 } else { 
 
 Toast.makeText(SplashActivity.this, "Not Logged In", Toast.LENGTH_LONG).show(); 
 
 } 
 
 } 
 
 @Override 
 public void handleFault(BackendlessFault fault) { 
 
 Toast.makeText(SplashActivity.this, "Error " + fault.getMessage(), Toast.LENGTH_LONG).show(); 
 
 } 
});


This sends the “Not Logged In” toast to the screen, even though the user is logged in.

Could you show me how the Async method would be written with the stayLoggedIn parameter?

Thanks!

Chris

I fixed it!!! All I had to do was add the “true” parameter to the loginWithFacebookSDK() method. For anyone else dealing with the same issue, here is the fix. Note the “true” at the bottom of the code field. True in this case is a boolean for “stay logged in”.

Backendless.UserService.loginWithFacebookSdk( LoginActivity.this, facebookFieldsMappings, permissions, callbackManager, new AsyncCallback<BackendlessUser>() 
{ 
 @Override 
 public void handleResponse( BackendlessUser backendlessUser ) 
 { 
 Intent intent = new Intent(LoginActivity.this, SplashActivity.class); 
 startActivity(intent); 
 LoginActivity.this.finish(); 
 } 
 
 @Override 
 public void handleFault( BackendlessFault backendlessFault ) 
 { 
 Toast toast = Toast.makeText( LoginActivity.this, backendlessFault.toString(), Toast.LENGTH_LONG ); 
 toast.show(); 
 } 
}, true );