Hi dear Backendlesses,
trying to make the login of a user persistent.
in my onCreate I’ve put the initApp and then this code:
String userToken = UserTokenStorageFactory.instance().getStorage().get();
if( userToken != null && !userToken.equals( "" ) ) { // user login is available, skip the login activity/login form }
//String first_name = (String) user.getProperty("first_name");
String usernamestring = (String) user.getProperty("email");
Toast.makeText(MainActivity.this, String.format("Welcome token " + usernamestring), Toast.LENGTH_LONG).show();
Intent intent = new Intent(MainActivity.this, FeedActivity.class);
startActivity(intent);
}
then in my onLogin I’ve put the following code:
public void onLogin(View view){
Toast.makeText(MainActivity.this, String.format("signing in..."), Toast.LENGTH_LONG).show();
textboxusername = (EditText) findViewById(R.id.editTextMail);
textboxpassword = (EditText) findViewById(R.id.editTextPassword);
final String usernamestring = textboxusername.getText().toString();
String passwordstring = textboxpassword.getText().toString();
Backendless.UserService.login( usernamestring, passwordstring, new AsyncCallback<BackendlessUser>()
{
public void handleResponse( BackendlessUser user )
{
// user has been logged in
Toast.makeText(MainActivity.this, String.format("Welcome " + user.getProperty("email")), Toast.LENGTH_LONG).show();
AsyncCallback<Boolean> isValidLoginCallback = new AsyncCallback<Boolean>()
{
@Override
public void handleResponse( Boolean response )
{
System.out.println( "[ASYNC] Is login valid? - " + response );
Toast.makeText(MainActivity.this, String.format( "[ASYNC] Is login valid? - " + response ), Toast.LENGTH_LONG).show();
}
@Override
public void handleFault( BackendlessFault fault )
{
System.err.println( "Error - " + fault );
Toast.makeText(MainActivity.this, String.format( "Error - " + fault ), Toast.LENGTH_LONG).show();
}
};
Backendless.UserService.isValidLogin(isValidLoginCallback);
Intent intent = new Intent(MainActivity.this, FeedActivity.class);
startActivity(intent);
}
public void handleFault( BackendlessFault fault )
{
// login failed, to get the error code call fault.getCode()
Toast.makeText(MainActivity.this, String.format(fault.getMessage()), Toast.LENGTH_LONG).show();
}
}, true);
}
I thought that will work, but when I close my app it doesn’t save my current user login.
I do get a [ASYNC] Is login valid? - true response though.
what am I missing ?
thanks! love you guys (and Kate)!