I am using an authentication system in Android 4.2 using an authentication example. In my application, I have a MenuActivity function with the Login option. If you click this option and the user has not logged in already, my authentication system will start and the AuthenticationActivity function will be displayed.
When the login ends, I want to execute some code in MenuActivity so that it knows that the user is logged in. I created a callback to do this, but it never called. Logging in works fine, if I close the application and run it again, it detects the user as registered.
In my Activity menu, I have the following:
public void login() { if(mAccount != null) Toast.makeText(MenuActivity.this, getString(R.string.account_exists), Toast.LENGTH_LONG).show(); else{ mAccountManager.addAccount(ACCOUNT_TYPE, AUTHTOKEN_TYPE, null, null, this, completeCallbackLogin, null); } }
In my AuthenticatorActivity (called LoginActivity) I do the following:
Account account = new Account(mUsername, ACCOUNT_TYPE); try{ mAccountManager.addAccountExplicitly(account, mPassword, newBundle()); }catch(Exception e){ e.printStackTrace(); return; } final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, ACCOUNT_TYPE); intent.putExtra(AccountManager.KEY_PASSWORD, mPassword); intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAuthToken); intent.putExtra(AccountManager.KEY_BOOLEAN_RESULT, true); LoginActivity.this.setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); LoginActivity.this.finish();
As I said, my callback is never called. Why is this?
[EDIT]
I just noticed that if I run the application again (Eclipse-> Run), the callback is called immediately before closing my application, which will be installed again.
[/ EDIT]