简体   繁体   English

Android-调用BroadcastReceiver时是否实例化Application类?

[英]Android - Is the Application class instantiated when a BroadcastReceiver is called?

is the Application class instantiated when a BroadcastReceiver is called? 调用BroadcastReceiver会实例化Application类吗? I have some logic in the custom Application class which is needed before the logic in onReceive of a BroadcastReceiver is run. 在自定义Application类中,我有一些逻辑,在运行BroadcastReceiver onReceive中的逻辑之前,需onReceive The documentation says the Context argument in the onReceive method is the Context in which the receiver is running. 该文档onReceive方法中的Context参数是接收器在其中运行的Context I was not sure if it is the application in which the receiver is defined(statically in the manifest) or not. 我不确定是否是定义接收者的应用程序(静态在清单中)。

Yes. 是。 The documentation for Application.onCreate notes: Application.onCreate的文档说明:

Called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created. 在创建任何活动,服务或接收者对象(不包括内容提供者)之前,在应用程序启动时调用。 If onCreate is called before your receiver is, it is by default instantiated first. 如果onCreate在接收者之前被调用,则默认情况下将首先实例化它。

[1] http://developer.android.com/reference/android/app/Application.html#onCreate() [1] http://developer.android.com/reference/android/app/Application.html#onCreate()

To answer this question you can try an expriment. 要回答这个问题,您可以尝试一个实验。 Just extends the Application and log it's class in onReceive() : 只需扩展Application并将其类记录在onReceive()中:

Log.d(TAG, "Context is " + context.getClass().getName());

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

相关问题 在Android中屏幕锁定时未调用BroadcastReceiver - BroadcastReceiver not called when screen locked in Android 永远不会调用Android BroadcastReceiver - Android BroadcastReceiver is never called android BroadcastReceiver 调用了两次 - android BroadcastReceiver called twice 安卓系统 <receiver> -不调用BroadcastReceiver - Android <receiver> - BroadcastReceiver not called 永远不会调用Android BroadcastReceiver - Android BroadcastReceiver is never called 是否保证在调用定义的引导接收器之前实例化Application类 - Is the Application class guaranteed to be instantiated before a defined boot receiver is called Redmi 2中的Internet处于关闭状态时未调用Android BroadcastReceiver的onReceive - Android BroadcastReceiver's onReceive not called when internet is OFF in redmi 2 当BroadcastReceiver是内部类时,为什么我的BroadcastReceiver的onReceive没有被调用? - Why doesn't my BroadcastReceiver's onReceive get called when the BroadcastReceiver is an inner class? Android:当应用程序处于后台时,未从 BroadcastReceiver 调用活动 - Android : Activity not called from BroadcastReceiver when app is in background Android:该应用程序的Internet BroadcastReceiver - Android: Internet BroadcastReceiver for the application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM