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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With