[英]Why does ContentProvider.onCreate() get called before Application.onCreate()?
I registered a ContentProvider in AndroidManifest.xml, and the ContentProvider.onCreate() was called even before the Application.onCreate().我在 AndroidManifest.xml 中注册了一个 ContentProvider,甚至在 Application.onCreate() 之前就调用了 ContentProvider.onCreate()。 I don't understand this behavior, in my opinion, It's more natural that Application.onCreate() be called before any of the components in the application.
我不理解这种行为,在我看来,在应用程序中的任何组件之前调用 Application.onCreate() 更自然。 Could someone tell me the timing of Application.onCreate() and other components' onCreate() gets called?
有人能告诉我 Application.onCreate() 和其他组件的 onCreate() 被调用的时间吗?
According a Google's issue it's how this should work (although documentation is wrong).根据谷歌的问题,它应该如何工作(尽管文档是错误的)。
There's another question that have a workarround that can help you.还有一个问题有一个可以帮助你的解决方法。
It is exactly how it should work.这正是它应该如何工作的。
Documentation of Application
class was updated starting from Android 4.2 and it says that Application#onCreate()
Application
类的文档从 Android 4.2 开始更新,它说Application#onCreate()
Called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created.
在应用程序启动时调用,在创建任何活动、服务或接收器对象(不包括内容提供者)之前。
When an Android app process is first started, there is well-defined order of operations: 首次启动Android应用程序进程时,会有明确定义的操作顺序:
Please read more: https://firebase.googleblog.com/2016/12/how-does-firebase-initialize-on-android.html 请阅读更多内容: https : //firebase.googleblog.com/2016/12/how-does-firebase-initialize-on-android.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.