在 AccountManager 中添加帐户可能会导致死锁
当我看到用户在帐户管理器中没有帐户时,我尝试执行以下操作将用户发送到帐户设置活动并让他们创建帐户。
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);
这会抛出一个 IllegalStateException
,说明从主线程调用它可能会导致死锁。执行此类操作的最佳方法是什么?有人有一个很好的代码示例吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html
您可以这样使用它...实现身份验证服务和活动,登录后,您可以按活动在共享首选项中保存凭据...
可以通过意图正常调用身份验证活动
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