Adding an account to AccountManager may result in deadlock

When I see that the user does not have accounts in the account manager, I try to do the following to send the user to the account settings action and create an account for him.

AccountManagerFuture<Bundle> addAccount = accountManager.addAccount(ACCOUNT_TYPE, TOKEN, null, null, MyActivity.this, // activity null, // callback null); // handler Intent result = (Intent) addAccount.getResult().get(AccountManager.KEY_INTENT); startActivity(result); 

This throws a IllegalStateException , calling it from the main thread, can lead to a deadlock. What is the best way to perform this type of operation, and does anyone have a good example of code in action?

+8
android accountmanager
source share
1 answer

http://developer.android.com/resources/samples/SampleSyncAdapter/index.html you can use it this way ... implement the service and auth activity, and after logging in you can save the credentials in the general activity settings. ..

The auth function can usually be called using intent

+1
source share