authentication - Automatically logout when user deletes Android Authenticator account from settings -
I have developed an application that uses the Android Authenticator API ( Account Manager ), then I can add or remove accounts through settings screen.
If I log out of my application, then I can delete the program and return the user to account activator activity . However, if the user has wiped the account manually from the settings screen, I would like to see that my app (which is running) detected this condition and automatically opened again when logged out.
I thought overwriting onResume each activity method (or expansion of a new activity group) and ask Authenticator with getAuthTokenByFeatures , so when If the application is resume it will ask the user to login if the account was deleted even though I am new to Android and do not know that this is a good way.
Well, I've discovered addOnAccountsUpdatedListener method in the class.
By using that, I answer my question. The onCreate method of the main activity of my application:
accountsListener = new OnAccountsUpdateListener () {@Override public void onAccountsUpdated (account [] account) {account [] myAccounts = mAccountManager.getAccountsByType (AccountGeneral. ACCOUNT_TYPE); If (myAccounts.length == 0) {// account Intent i = Navin Intent (Mtiotiakstii, Promptoginaktivtikclas) has been removed; StartActivity (i); End(); } Return; }}; MAccountManager.addOnAccountsUpdatedListener (accountsLister, empty, true);
Comments
Post a Comment