Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ContentProvider destruction/lifecycle

I'm curious if someone can explain the lifecycle of a ContentProvider. I'm especially interested in if, when and under what circumstances a provider is destroyed. That doesn't appear to be covered by the documentation.

The ContentProvider section of this article talks about documentation being hard to come by but it includes a link to a Google Groups discussion where an engineer at Google left a quick response, stating that "content providers are never destroyed. They exist for the entire lifetime of their process."

Okay, so maybe a ContentProvider lives as long as its process but how long does its process live? Suppose I have an application that provides a ContentProvider and a query from another application is the only reason my ContentProvider's process was created (i.e., there's not also an Activity or Service running.) Would that process really continue to run indefinitely? When Android is running low on resources, it destroys components like Services. Are ContentProviders not also candidates for being destroyed when resources are tight?

like image 515
spaaarky21 Avatar asked Jun 04 '14 20:06

spaaarky21


People also ask

What is a Contentprovider and what is it typically used for?

A content provider manages access to a central repository of data. A provider is part of an Android application, which often provides its own UI for working with the data. However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object.

What is Android application lifecycle?

An Android activity goes through six major lifecycle stages or callbacks. These are: onCreate() , onStart() , onResume() , onPause() , onStop() , and onDestroy() . The system invokes each of these callbacks as an activity enters a new state.

What is content provider in Android?

Content providers are one of the primary building blocks of Android applications, providing content to applications. They encapsulate data and provide it to applications through the single ContentResolver interface. A content provider is only required if you need to share data between multiple applications.


1 Answers

I'm especially interested in if, when and under what circumstances a provider is destroyed

It is created when your process is started (even before your Application object is created), and it lives until the process is terminated.

how long does its process live?

That varies based upon what is going on with the app, the user, and the device.

Would that process continue to run indefinitely?

No.

When the system is running low on resources, Android destroys components like Services.

No, it does not. When the system is running low on RAM, Android terminates processes.

Are ContentProviders not also candidates for being destroyed when resources are tight?

A process containing a ContentProvider can be terminated, whether due to low memory conditions, old age, user action, etc.

like image 131
CommonsWare Avatar answered Oct 24 '22 00:10

CommonsWare