7

I have a ContentProvider which is declared in the Manifest, when is it really created ? When the application is launched but before launching the first activity ? When the first query/update/insert is done ? When ?

fedj
  • 3,452
  • 1
  • 22
  • 21

2 Answers2

8

From http://developer.android.com/reference/android/content/ContentProvider.html#onCreate():

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. It must not perform lengthy operations, or application startup will be delayed.

James Wald
  • 13,626
  • 5
  • 52
  • 63
-1

When the first query/update/insert is done. Check this

Update: android documentation is invalid in this regard. Valid behaviour is descirbed here https://stackoverflow.com/a/11858493/657487

ContentProvider created when app starts. So, it might be wise to make onCreate() lightweight

sandrstar
  • 12,503
  • 8
  • 58
  • 65
Tushar Tarkas
  • 1,592
  • 13
  • 25
  • 1
    It will be created before application's created. https://stackoverflow.com/questions/11788838/why-does-contentprovider-oncreate-get-called-before-application-oncreate – shanwu Jul 18 '17 at 04:31