n179911
n179911

Reputation: 20341

How to instantiate my Content Provider up front?

In my application, I have created a ContentProvider. Is there a way for me to instantiate this ContentProvider when my apk is started?

Right now, the ContentProvider only instantiates when someone does a query.

Upvotes: 1

Views: 652

Answers (1)

Reto Meier
Reto Meier

Reputation: 96916

What exactly do you mean by 'instantiate' your Content Provider? Generally you should be using a Content Resolver to access Content Providers rather than instantiating them directly.

If you want to initiate a query against your Content Provider when your application is first started, you can extend the Application class and override the onCreate method, making a query to your Content Provider from there.

If you go that way, you'll also need to modify the <application> node in your manifest to include an android:name attribute that specifies your new Application class implementation.

Upvotes: 2

Related Questions