Using SyncAdapter without creating an account
Asked Answered
S

1

8

My app allows people to use and manage their data regardless they're logged in. Though, as I uniquely identify each device, I want to sync data from my anonymous users (not logged ones) as well. So, I was wondering if it is a good practice to create an anonymous account in this case, since SyncAdapters only work with accounts.

Should I create an account for my anonymous users or should I sync their data with threads/AsyncTasks/Loaders? In particular, is there any way to make ContentResolver.requestSync() work without the need of an account?

Serration answered 30/8, 2012 at 21:7 Comment(1)
I would recommend to use the same synchronization process for both authenticated and anonymous users. requestSync requires an account. If you want to use this, create an anonymous account.Elidaelidad
A
6

Using the SyncAdapter/AccountManager in Android is frankly more trouble than it's worth. That specific pattern is best used only when you expect a large number of other applications to want to share your account data (e.g. Twitter or Facebook).

I'd suggest you simply write your own background Service implementation to do your syncing. You can use an AlarmManager to notify the service to sync periodically. Otherwise, you can simply sync when the user opens your application using a basic AsyncTask.

Arizona answered 6/9, 2012 at 4:26 Comment(1)
I can believe that using the SyncAdapter/AccountManager is more trouble than it ought to be, considering what a common task is caching representations of some server's resource....but is it really more trouble than writing your own Service?Molina

© 2022 - 2024 — McMap. All rights reserved.