Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Killing app <my service> (pid 1724) because provider <my provider> is in dying process <my app>

Tags:

android

A Provider is implemented in application and application updates provider data and triggers a remote service which queries the provider to retrieve the stored values.The application is closed after sometime but service keep on accessing the content provider.At some point the following error is thrown in logcat and the remote service is crashed.

"Killing app (pid 1724) because provider is in dying process "

I googled for this error and couldn't find information about why this error occurs.

UPDATE: In one of the places context returned by getApplicationContext is used instead of Service to get contentresolver to query the content provider. Does it cause any problem?

like image 762
Suresh Avatar asked Sep 03 '10 12:09

Suresh


2 Answers

Hmm, hard luck, no answers so far. I figured out what has caused the crash last week! I guess i should share that here.

Provider P is defined in application A which has a service S1 that disables the package and kills the package for some reason. Now there is another application B that has service S2 and uses the provider P. At some point service S1 disables some components of application A package and kills the process, that makes provider to find all the processes that are connected to it and kills those one by one, this makes the process in which application B is running to die with error "Killing app because provider is in dying process.

Moving the provider to a new application solved the issue so that it runs in its own process solved the issue.

like image 65
Suresh Avatar answered Oct 24 '22 11:10

Suresh


TL;DR

Use unstable ContentProviderClient.

Here is explanation from other author: https://stackoverflow.com/a/33562256/87383

LONG READ

Faced the same issue and resolved (workaround) it next way:

First of all you should understand the difference between ContentResolver.registerContentObserver and ContentResolver.query

So, ContentResolver.registerContentObserver simply connects your local ContentObserver instance with ContentService. It's achieved by creating a "bridge" using ContentObserver.Transport class instance (which is basically a binder) and passing it to the ContentService. See ContentObserver.getContentObserver()

Why it's important ? Because those observers are not managed (registered) by ActivityManagerService.

So, what's special about ContentResolver.query method ? To answer this question we have to look at ContentProviderClient. Because actual queries are performed through ContentProviderClient instances which are responsible for contacting with remote ContentProvider.

And there are two "types" of ContentProviderClient - stable and unstable. Unstable clients are managed by your application. But stable one is managed by Android for you so when application is stopped, ActivityManager knows that it's time to kill all clients.

See this commit for more details on unstable content provider clients: https://android.googlesource.com/platform/frameworks/base/+/6ae8d1821822296df0606c9cd1c46708cc21cb58

like image 24
Oleksandr Avatar answered Oct 24 '22 10:10

Oleksandr