Add Account in AccountManager can lead to deadlock
Asked Answered
K

1

8

When I see that the user has no accounts in account manager I'm trying to do the following to send the user to the account settings activity and have them create an account.

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 is throwing an IllegalStateException saying calling this from your main thread can lead to deadlock. What is the best way to perform this type of operation, and does anyone have a good code example of this in action?

Keeping answered 13/5, 2011 at 17:6 Comment(3)
Why not take them directly to your login screen? That seems to be the usual thing (Twitter/Facebook etc..)Photomechanical
@Joseph I'm using AccountManager to log the users in. Do you have an example of how to do that?Keeping
Did you solve this problem eventually? How?Huneycutt
D
1

http://developer.android.com/resources/samples/SampleSyncAdapter/index.html you could use it this way ... implement auth service and activity, and after logging in, you could save credentials at shared preferences by activity ...

auth activity can be invoked normally by intent

Decidua answered 15/2, 2012 at 17:33 Comment(2)
"you could save credentials at shared preferences by activity" => a joke? The main goal of the accountManager is to avoid you to store the credentials in your app!Zebadiah
I meant some login token ;)Decidua

© 2022 - 2024 — McMap. All rights reserved.