Sunday, April 21, 2013

[android help] What should I use Android AccountManager for?

What should I use Android AccountManager for? - Stack Overflow








Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















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 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.


With AccountManager / SyncAdapter / ContentProvider:


  • 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 (no sync when network is down)

  • ContentProvider is the only way to share data across applications

  • ContentProvider schedules the database access in a background thread, preventing 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

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


  • If you only want to store data, you should consider a simpler mechanism for data storage

  • If you only want to get only resource, you can consider a Service / Alarm

  • only available from API >= 7

























From http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/:



The first piece of the puzzle is called an Account Authenticator, which defines how the user’s account will appear in the “Accounts & Sync” settings. Implementing an Account Authenticator requires 3 pieces: a service that returns a subclass of AbstractAccountAuthenticator from the onBind method, an activity to prompt the user to enter their credentials, and an xml file describing how your account should look when displayed to the user. You’ll also need to add the android.permission.AUTHENTICATE_ACCOUNTS permission to your AndroidManifest.xml.























The AccountManager class is integrated with your phone accounts. So if you follow all the guides and get it working correctly you'll see your accounts under the menu "Settings->accounts and synch". From there you can customize them or even delete them. Furthermore the accountManager has a cache of the authentication tickets for your accounts. This can be used also if you don't plan to synchronize your account (as far as i know).


If you don't want your accounts to appear under that menu you shouldn't use the AccountManager and store the accounts data elsewhere (maybe in the shared preferences) http://developer.android.com/guide/topics/data/data-storage.html






















I will disagree with some of whats been written as I have implemented AccountManager without having to use SynchAdapter or a content provider.


The password is saved encrypted SHA1-256 and account auth tokens are generated which are used to access a remote resource.


Whatever implementation strategy you use, ensure you follow the tutorial and setup the xml preferences correctly.




















default







.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...