Android app killed from SyncAdapter

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

+5
source share
1 answer

Perhaps you are working on a TransactionTooLargeException ? This happens when the data that is part of Intent takes up more space than the 1 MB limit. If you see “Contacts” in your journal, this may be due to a user database that is too large. The sad thing about this exception is that this happens at the system level. Your application gets killed without getting the opportunity to catch (or: report) the problem. The only way to catch this exception is to follow the logarithm.

Regarding the question of how to prevent the SyncAdapter from crashing. Are you using SyncAdapter in a separate process? If you just follow the sample / training code, then you. If not, check out android:process=":sync" on the page. When launched in a separate process, crashes in the SyncAdapter should not affect the rest of your application. At least not directly. Your users will see the "application crash" dialog, but application components that work in other processes will continue to work normally.

+2
source

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


All Articles