我应该采用Android的AccountManager的是什么? [英] What should I use Android AccountManager for?

查看:312
本文介绍了我应该采用Android的AccountManager的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过的AccountManager在Android SDK,它用于存储账户信息。因此,我找不到它是什么用于任何一般性讨论。有谁知道什么背后的AccountManager的意图是任何有益的讨论,什么能带给你?任何意见是什么类型的账户,这是适合?请问这是哪里,你就会把你的用户的账户信息进行一般性的服务?

I've seen AccountManager in the Android SDK and that it is used for storing account information. Thus, I cannot find any general discussion of what it is intended for. Does anyone know of any helpful discussions of what the intention behind AccountManager is and what it buys you? Any opinions of what type of Accounts this is suitable for? Would this be where you'd put your user's account information for a general web service?

推荐答案

这个问题是有点老了,但我认为它仍然是良好的兴趣。

This question is a bit old, but I think it is still of good interest.

的AccountManager SyncAdapter 的ContentProvider 一起去。您不能使用的AccountManager 没有 SyncAdapter 。你不能使用<一个href="http://stackoverflow.com/questions/5146272/sync-adapter-without-account"><$c$c>SyncAdapter没有的AccountManager 你不能有一个 SyncAdapter 没有的ContentProvider 。据我所知,您可以使用的ContentProvider 没有其他人。

AccountManager, SyncAdapter and ContentProvidergo together. You cannot use an AccountManager without a SyncAdapter. You cannot use a SyncAdapter without an AccountManager. You cannot have a SyncAdapterwithout a ContentProvider. As far as I know, you can use the ContentProvider without the others.

使用的AccountManager / SyncAdapter / 的ContentProvider

  • 的AccountManager 为用户提供了一个中心点(设置>帐户)来定义他们的凭据
  • 在Android的决定时,同步可以通过 SyncAdapter 来完成。这可以很好地优化电池(无同步完成当网络出现故障,例如)
  • 的ContentProvider 是一个方便的方式来共享应用程序之间的数据 注意:有进程间通信在Android 其他方法
  • <打击> 的ContentProvider 时间表在后台线程数据库访问的的 AsyncQueryHanlder 帮助查询的ContentProvider 在后台线程,preventing应用程序无响应(ANR)的错误,而不是要求您显式处理线程。
  • 的ContentProvider 关系到 ContentResolver的的观察:这意味着它很容易在内容改变通知的意见
  • AccountManager gives users a central point (Settings > Accounts) to define their credentials
  • Android decides when synchronization can be done via SyncAdapter. This can be good to optimize battery (no sync is done when network is down, for instance)
  • ContentProvider is a convenient way to share data across applications Note: there are other methods of inter-process communication on Android.
  • ContentProvider schedules the database access in a background thread The AsyncQueryHanlder helps to query the ContentProvider in a background thread, preventing Application Not Responsive (ANR) errors while not requiring you to explicitly handle threading.
  • ContentProvider ties into ContentResolver's observer: this means it is easy to notify views when content is changed

底线:框架的AccountManager / SyncAdapter / 的ContentProvider 帮助,如果你想从网络资源同步数据。假/ <一href="http://stackoverflow.com/questions/5358391/how-do-i-implement-an-account-on-android-without-a-syncadapter">Dumb如果你并不真的需要这些作品之一需要实现。此外

Bottom line: the framework AccountManager / SyncAdapter / ContentProvider helps if you want to synchronize data from a web resource. Fake/Dumb implementations are required if you don't really need one of these pieces. Also

  • 如果您只想存储数据,你应该考虑href="http://developer.android.com/guide/topics/data/data-storage.html" rel="nofollow">简单的机制
  • 如果你只想要得到的唯一资源,你可以考虑服务/闹钟
  • 只能从API> = 7(这并不重要了)

这篇关于我应该采用Android的AccountManager的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆