BroadcastReceiver 工作如何属于应用程序状态?

How does BroadcastReceiver work belong to app state?

我的问题是关于接收器在应用程序处于 'Died' 时的行为 - 接收器是否也随之死亡,或者它们仍在内存中工作?

我的问题是关于这种情况 - 我不能听动作 'App is destroyed' 和小心地做 'unregisterReciever'。 所以我想知道 - 内存中的接收器发生了什么属于应用程序状态。

PS - 在 Activity 的 'onstop' 中取消注册等方法不适合我的情况。

嗯!接收方是否会die/destroy(执行方面)的行为取决于您注册的接收方类型。如果您在应用程序清单 Manifest-declared receivers 中注册 BroadcastReceiver,那么在应用程序关闭后,BroadcastReceiver 不会像官方文档所说的那样死掉。

The system creates a new BroadcastReceiver component object to handle each broadcast that it receives. This object is valid only for the duration of the call to onReceive(Context, Intent). Once your code returns from this method, the system considers the component no longer active.

If you declare a broadcast receiver in your manifest, the system launches your app (if the app is not already running) when the broadcast is sent.

其他类型的 BroadcastRecievers 是 Context-registered receivers。 上下文注册的接收器是那些接收器:

receive broadcasts as long as their registering context is valid. For an example, if you register within an Activity context, you receive broadcasts as long as the activity is not destroyed

在这种情况下,当链接组件的上下文被销毁时,BroadcastReciever 也将被销毁。