简体   繁体   English

android初始化中的内容提供者

[英]content provider in android initialization

I'm looking at the documentation of creating a content provider and it's stated that for the onCreate method, the Android system calls this method immediately after it creates your provider.我正在查看创建内容提供程序的文档,并指出对于onCreate方法,Android 系统在创建您的提供程序后立即调用此方法。 and your provider is not created until a ContentResolver object tries to access it.并且在 ContentResolver 对象尝试访问它之前不会创建您的提供者。

Despite this, when adding a content provider via the manifest, I noticed that the onCreate method is called immediately after the app is started, regardless of whether the provider is accessed or not.尽管如此,在通过清单添加内容提供者时,我注意到无论是否访问提供者,都会在应用程序启动后立即调用onCreate方法。 https://developer.android.com/guide/topics/providers/content-provider-creating https://developer.android.com/guide/topics/providers/content-provider-creating

Is this behavior consistent/documented anywhere?这种行为是否一致/记录在任何地方?

Thanks谢谢

Guy盖伊

If you refer to API doc: https://developer.android.com/reference/android/content/ContentProvider#onCreate() it is states that如果您参考 API 文档: https : //developer.android.com/reference/android/content/ContentProvider#onCreate()它指出

This method is called for all registered content providers on the application main thread at application launch time.在应用程序启动时,在应用程序主线程上为所有已注册的内容提供程序调用此方法。

It is hard to say what cause your provider be initialized without referencing your code.很难说是什么原因导致您的提供程序在不引用您的代码的情况下被初始化。 Also, I believe the guidelines (the link you posted) is more likely out of dated compare to API doc (I reference to).此外,我相信与 API 文档(我参考)相比,指南(您发布的链接)更有可能过时。 In my case, for instance, there is boot receiver, and since my app invoked by boot receiver, the content provider gets initialized as well, just like API doc said.例如,在我的情况下,有启动接收器,并且由于我的应用程序由启动接收器调用,因此内容提供程序也会被初始化,就像 API 文档所说的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM