According to the Official documentation
onCreate() method of the content provider is called by Android's system call immediately after it creates the provider. And since the provider isn't created until a ContentResolver object tries to access it. How my onCreate is getting called before I tried accessing it using contentResolver? (Note: I am not even accessing the provider still its onCreate getting called)
The documentation for Provider.onCreate()
that you linked to explicitly states:
Implement this to initialize your content provider on startup. This method is called for all registered content providers on the application main thread at application launch time.
So Android will call onCreate()
on all content providers immediately on application launch. Obviously it cannot call onCreate()
until the content provider is instantiated, so that means that immediately on application launch, Android will instantiate all content providers and call onCreate()
on all of them.
Your application will have to deal with this appropriately.