简体   繁体   English

为什么 ContentProvider.onCreate() 在 Application.onCreate() 之前被调用?

[英]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应用程序进程时,会有明确定义的操作顺序:

  1. Each ContentProvider declared in the manifest is created, in priority order . 清单中声明的​​每个ContentProvider都按优先级顺序创建。
  2. The Application class (or custom subclass) is created. 创建Application类(或自定义子类)。
  3. If another component that was invoked via some Intent, that is created. 如果是通过某个Intent调用的另一个组件,则创建该组件。

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.

相关问题 在Application.onCreate代码之前调用NotificationListenerService - NotificationListenerService called before Application.onCreate code Android Activity::onCreate 在 Application.onCreate 之前调用 - Android Activity::onCreate called before Application.onCreate 在BroadcastReceiver.onReceive(..)之前是否会调用Application.onCreate(Bundle)? - Will Application.onCreate(Bundle) be called before BroadcastReceiver.onReceive(..)? 应用程序可以在Application.onCreate()之前获取Fragment.onAttached()吗? - Can the app get Fragment.onAttached() before Application.onCreate()? Application.onCreate被多次调用 - Application.onCreate called more than once Application.onCreate() 未在调试版本中调用 - Application.onCreate() not called in debug build 确定调用Application.onCreate()的进程 - Determine by which process Application.onCreate() is called 是否可以从ContentProvider.onCreate()启动服务? - Is it OK to start a service from the ContentProvider.onCreate()? 在Application.onCreate()上的BroadcastReceiver - BroadcastReceiver on Application.onCreate() 如果应用程序闲置了数小时并被OS破坏,是否在Activity.onResume之前调用Application.onCreate? - Is Application.onCreate called before Activity.onResume if app has been idle for hours and destroyed by OS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM