I have a SyncAdapter that gets called during the initial Login / Registration process, which touches contacts to find users who are already using the system.
While the SyncAdapter is running, the application is killed almost every time (9 out of 10 times) on a specific device (Moto G) .
My initial thoughts were that the application is being killed due to the limited available RAM of the device. So, I tried this to confirm the theory:
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); ActivityManager activityManager = (ActivityManager) getContext() .getSystemService(Context.ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); long availableMegs = mi.availMem / 1048576L; Log.d(TAG, "Available: " + availableMegs); Log.d(TAG, "Low Memory: " + mi.lowMemory); }
And it turns out that RAM cannot be a problem, since the logs look like this:
03-09 11:38:34.444 19193-21339/mypackage.sandbox D/SyncAdapter: Available: 252 03-09 11:38:34.445 19193-21339/mypackage.sandbox D/SyncAdapter: Low Memory: false
Further in the logs I found this:
03-09 11:38:35.233 865-1610/? I/ActivityManager: Killing 19193:mypackage.sandbox/u0a579 (adj 0): depends on provider com.android.providers.contacts/.ContactsProvider2 in dying proc android.process.acore
It seems that the application is being killed because the application / contact provider is dying.
I'm not sure how relevant this thread I found on reddit.
How can I prevent the killing of my application while it is still in FOREGROUND?
In one case, I think it is possible if I can postpone the notification that the contacts have been changed. This will prevent termination by the contact provider and murder, in turn, my expression will not be killed. See paragraph No. 7 in this answer . If so, how can I postpone a notification?
Update:
I even made sure that the notification of contacts is postponed without changing contacts. However, the problem persists.
Any help is appreciated. Thanks