android - SyncAdapter process killed when app process is terminated -
why syncadapter process (:sync) killed when app swiped app switcher list ? thought whole intention here keep them decoupled.
edit:
following code used. muploadtask
asynctask
im executing reads information sqlite table (using getcontext().getcontentresolver()
) , uploads relevant data backend (using httppost
). straight forward.
also, implemented 1 onsynccanceled()
since syncadapter
doesnt support syncing of multiple accounts in parallel.
public class syncadapter extends abstractthreadedsyncadapter implements uploadtasklistener { private static final string tag = syncadapter.class.getsimplename(); private static volatile uploadtask muploadtask; /** * set sync adapter */ public syncadapter(context context, boolean autoinitialize) { super(context, autoinitialize); } /** * set sync adapter. form of * constructor maintains compatibility android 3.0 * , later platform versions */ public syncadapter( context context, boolean autoinitialize, boolean allowparallelsyncs) { super(context, autoinitialize, allowparallelsyncs); } @override public void onperformsync(account account, bundle extras, string authority, contentproviderclient provider, syncresult syncresult) { mhlog.logi(tag, "onperformsync"); contentresolver.setsyncautomatically(account, authority, true); if (muploadtask == null) { synchronized (syncadapter.class) { if (muploadtask == null) { muploadtask = new uploadtask(getcontext(), this).executeonsettingsexecutor(); mhlog.logi(tag, "onperformsync - running"); } } } } @override public void onsynccanceled() { mhlog.logi(tag, "onsynccanceled"); if(muploadtask != null){ muploadtask.cancel(true); muploadtask = null; } }
from documentation:
syncs can cancelled @ time framework. example sync not user-initiated , lasts longer 30 minutes considered timed-out , cancelled. framework attempt determine whether or not adapter making progress monitoring network activity on course of minute. if network traffic on window close enough 0 sync cancelled. can request sync cancelled via
cancelsync(account, string)
orcancelsync(syncrequest)
.a sync cancelled issuing
interrupt()
on syncing thread. either code inonperformsync(account, bundle, string, contentproviderclient, syncresult)
must checkinterrupted()
, or you must override 1 ofonsynccanceled(thread)
/onsynccanceled()
(depending on whether or not adapter supports syncing of multiple accounts in parallel). if adapter not respect cancel issued framework run risk of app's entire process being killed.
are making sure honoring rules of syncadapter framework?
additionally, nice see of code drill down why framework cancelling sync...
Comments
Post a Comment