I'm making an android library and I want to run some initialization code when the application starts.
In some cases, it might be a little difficult for the developer(using my library) to implement a custom application class. AFAIK, the ContenProvider
codes start before application starts and does not need any custom implementation done by the developer using my library.
The question is, Can I use ContentProvider to run code at Application's start up?
I simply create a provider class:
class ExampleProvider : ContentProvider() {
override fun onCreate(): Boolean {
// run code at startup and do initialization
return true
}
...
// Ignore other methods and return null or 0
}
And add the manifest tag.
And it will run before the application starts up. (Without the need of Custom Application class) But will it always behave like this and run code before app starts? Is there any case that ContentProviders will not launch at app startup?
How an android library can run code at application startup, without asking developers to implement a custom Application class?
Recently Android has provided a startup library to initialize components at application startup. If you see the source code of that library, you will see they use ContentProvider
to start the library at startup.