SyncAdapter process terminates when application process terminates

Why is the SyncAdapter (: sync) process killed when the application is cleaned from the list of application switches? I thought the whole intention here is to keep them untied.

EDIT:

Below is the code. mUploadTaskexecutes AsyncTaskim, which reads information from the sqlite table (using getContext().getContentResolver()) and loads the corresponding data into the backend (using HttpPost). Very straight forward.

In addition, I implemented only one onSyncCanceled(), since mine SyncAdapterdoes not support synchronizing 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 up the sync adapter
 */
public SyncAdapter(Context context, boolean autoInitialize) {
    super(context, autoInitialize);
}

/**
 * Set up the sync adapter. This form of the
 * constructor maintains compatibility with Android 3.0
 * and 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;
    }
}
+4
source share
1 answer

From the documentation:

. , , 30 , - . , , , . , . cancelSync(Account, String) cancelSync(SyncRequest).

interrupt() . onPerformSync(Account, Bundle, String, ContentProviderClient, SyncResult) interrupted(), onSyncCanceled(Thread)/onSyncCanceled() ( , ). , , .

, SyncAdapter?

, , , ...

+1

Source: https://habr.com/ru/post/1626216/


All Articles