简体   繁体   English

Android内容提供商的实例化顺序

[英]Order of instantiation of Android Content Providers

For my application I need to have one Content Provider started before anything else. 对于我的应用程序,我需要先启动一个内容提供程序。 As far as I can tell the order is independent from the order in the AndroidManifest and is not alphabetical. 据我所知,顺序独立于AndroidManifest中的顺序,并且不是字母顺序的。

How can I control the order in which Android calls the onCreate() methods of the Content Providers? 如何控制Android调用内容提供者的onCreate()方法的顺序?

You need to set android:initOrder attribute. 您需要设置android:initOrder属性。 Below is what Android docs says 以下是Android文档所说的内容

android:initOrder The order in which the content provider should be instantiated, relative to other content providers hosted by the same process. android:initOrder相对于同一进程托管的其他内容提供者,应实例化内容提供者的顺序。 When there are dependencies among content providers, setting this attribute for each of them ensures that they are created in the order required by those dependencies. 如果内容提供者之间存在依赖关系,则为每个内容提供者设置此属性可确保按照这些依赖关系所需的顺序创建它们。 The value is a simple integer, with higher numbers being initialized first. 该值是一个简单的整数,其中较大的数字首先被初始化。

https://developer.android.com/guide/topics/manifest/provider-element.html#init https://developer.android.com/guide/topics/manifest/provider-element.html#init

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

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