Reputation: 1884
I'm currently working with a SyncAdapter that syncs data every 15 minutes. Is it possible to bind that Service to the Activity so I can show the user what the currenty sync status is?
I read in the documentation about IPC between services and activities that you can communicate with Messengers and Handlers. But I can't return a mMessenger.getBinder() in my SyncService onBind method because I have to return the syncAdapter.getSyncAdapterBinder() because of the SyncAdapter.
Upvotes: 0
Views: 687
Reputation: 3872
You can return a different IBinder
, depending on the action that was set for the Intent
. Check out my response to Android SyncAdapter: how to get notified of specific sync happened
Upvotes: 1
Reputation: 57
Try this definetiley work.
public class SyncService extends Service {
private static SyncAdapter sSyncAdapter = null;
private static final Object sSyncAdapterLock = new Object();
@Override
public void onCreate() {
synchronized (sSyncAdapterLock) {
if (sSyncAdapter == null) {
sSyncAdapter = new SyncAdapter(getApplicationContext(), true);
}
}
}
@Override
public IBinder onBind(Intent intent) {
return sSyncAdapter.getSyncAdapterBinder();
}
}
Upvotes: 1