As we know content provider loads on application run. But I want to make some operations before content provider will launch. How do I catch this operation? Before content provider's onCreate method would be called
The primary methods that need to be implemented are: onCreate() which is called to initialize the provider. query(Uri, String[], Bundle, CancellationSignal) which returns data to the caller. insert(Uri, ContentValues) which inserts new data into the content provider.
Accessing a provider. When you want to access data in a content provider, you use the ContentResolver object in your application's Context to communicate with the provider as a client. The ContentResolver object communicates with the provider object, an instance of a class that implements ContentProvider .
Content providers can help an application manage access to data stored by itself, stored by other apps, and provide a way to share data with other apps. They encapsulate the data, and provide mechanisms for defining data security.
After creating the content provider , specify the content provider in the manifest file. You can mention content provider using the tag. Inside the provider tag dont forget to mention the name and authorities attributes. This declaration should be ..
I think Ive found solution. Ive created my custom application class and overridden attachBaseContext method
<application android:name=".ApplicationController" ...>
public class ApplicationController extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); // some of your own operations before content provider will launch } }
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