Search code examples
androidbroadcastreceiver

Do broadcast receivers registered with an activity's context still respond if the activity goes into onStop?


If an activity registers a broadcast receiver, will it still be able to respond to the announcement if it has been put into the background (onStop())?


Solution

  • As stated in https://developer.android.com/guide/components/broadcasts#context-registered-receivers :

    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. If you register with the Application context, you receive broadcasts as long as the app is running.

    So I think it's the onDestroy method of the activity lifecycle that should be your concern.