Search code examples
androidauthenticationtokenbackendlessstay-logged-in

Backendless check if user is logged in


in my project I tried to use Backendless as server. The registration of the users works fine but everytime I start the App I have to login again.

I want to stay logged in even if I close the App as long as I don't press the Logoutbutton.

First I tried to use the function stayLoggedIn but I think it is not working.

I used the code example from Backendless to check if the usertoken is available and if the user is logged:

@Override
protected void onCreate( Bundle savedInstanceState )
{
    String userToken = UserTokenStorageFactory.instance().getStorage().get();
    if( userToken != null && !userToken.equals( "" ) )
    {  Intent i = new Intent(LoginActivity.this, MainActivity.class);
        startActivity(i);
         }

This is in the LoginAcitivity and if the user is logged in the LoginActivity should skipped an the MainAcitivity should start.

Running this project give me following error in the line 'String usertoken': java.lang.IllegalArgumentException: Init storage before use

I don't know how to solve the problem...

Thanks forward!


Solution

  • Make sure to call Backendless.initApp before you do anything else with the APIs.