I am implementing a login system for an Android application utilizing the built-in accounts system (with the AccountManager APIs).
All is well and good on Android 2.2+, but on Android 2.1 not including a SyncAdapter causes reboots in the account settings screen (see http://code.google.com/p/android/issues/detail?id=5009 and AccountManager without a SyncAdapter?)
To get around this I implemented a stub SyncAdapter, which just returns null
from IBinder onBind(Intent intent)
, and added the relevant stuff to the manifest. This resolves the reboot issue on Android 2.1.
However it introduces a further problem: after an account is added the Android system will, sometime later, initiate an account sync. Although no errors occur (indeed my SyncAdapter does nothing, it has no way to cause errors unless by returning null
), the sync icon stays stuck in the notification bar at the top. This results in the Android sync system maintaining a permanent wake-lock, preventing the device from sleeping.
The account does not list any syncable components in the account settings screen (under the 'Data and synchronization' header), and always displays 'Sync is off' for the sync status in the list of accounts (even while the sync icon is visible in the notifications bar). Disabling account syncing does not remove the problem. Removing the account stops the problem.
My guess is I should not be returning null. Should I be returning a basic implementation of ThreadedSyncAdapter? Any help getting an account system without an associated sync working properly on 2.1 and 2.2+ is much appreciated.
I sort of solved my own problem: you cannot return null
from the onBind
method of your service - you must return the IBinder
of an AbstractThreadedSyncAdapter
.
This has the undesired effect of adding an entry into the Data and Synchronization section of the account settings page, even though my implementation of AbstractThreadedSyncAdapter
does nothing; I was hoping to avoid this.
To summarize, in order to make use of the accounts system in Android you must:
IntentFilter
for android.content.SyncAdapter
.IBinder
of an AbstractThreadedSyncAdapter
implementation from it's onBind
method.ContentProvider
(can just be a stub implementation) that is referred to as the contentAuthority
in your SyncAdapter XML file.