这里先给出源码分析的结论:
ContentProvider 的 onCreate() 方法先于 Application 的 onCreate() 方法执行,晚于Application的onAttachContext()方法执行。
├── ActivityThread.handleBindApplication ├── LoadedApk.makeApplication ├── Instrumentation.newApplication ├── Instrumentation.newApplication ├── (Application)clazz.newInstance() //调用构造方法 ├── Application.attach ├── Application.attachBaseContext //调用attachBaseContext方法 ├── ActivityThread.installContentProviders ├── ActivityThread.installProvider ├── ContentProvider.attachInfo ├── ContentProvider.attachInfo ├── ContentProvider.onCreate // 调用 ContentProvider的onCreate方法 ├── Instrumentation.callApplicationOnCreate ├── Application.onCreate //调用Application的onCreate方法
结论:
调用顺序: Application 构造方法 –> Application.attachBaseContext –> ContentProvider.onCreate –> Application.onCreate –> Activity.onCreate