Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 17
    +1. if your Broadcast Receiver is in a fragment, register it using LocalBroadcastManager.getInstance(getActivity()).registerReceiver(onNotice); and unregister it using LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(onNotice); Commented May 30, 2013 at 6:47
  • 3
    Are you sure that LocalBroadcastManager is included in Android 3.0 and up? Can not find it anywhere except support lib Commented Nov 18, 2013 at 11:59
  • 5
    strangely, LBM is only included in the support library. Commented Dec 4, 2013 at 0:57
  • 2
    I believe you may want to move your lifecycle to onStop because in Android API 24+ with “Multi-Window/Split-View” (enabled by default on API 26+ affaicr), the activity not being interacted with is in the paused state. Source: developer.android.com/guide/topics/ui/… Commented Nov 17, 2017 at 21:30
  • 2
    @AJW I wouldn’t. There’s really no reason to do that (that I can think of). It really depends on your use case. For the most part, onStop/Start tends to be better given that a Dialog will trigger onPause and it may not be desired to “unsubscribe” to things (only to resubscribe moments later) because a Dialog appeared. Or in some cases yes, so… ensure that’s what you want ;) Commented Mar 29, 2018 at 1:25