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 ?
Asked
Active
Viewed 2,518 times
2 Answers
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
-
This matches my experience - `onCreate()` is called when the app starts up, long before any query/insert/updates are performed. – Alex MDC Nov 15 '13 at 14:25
-
1OK, so when is it being started up? On BOOT_COMPLETED...? – JohnyTex Sep 13 '18 at 07:24
-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
-
1It 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