0

After reading the question Basic communication between two fragments and the link given in the accepted answer, I have a question. Why don't I communicate between fragments using local broadcasts as long as I need to pass primitive types?

Maksim Dmitriev
  • 5,985
  • 12
  • 73
  • 138
  • 1
    Note that [LocalBroadcastManager](https://developer.android.com/reference/androidx/localbroadcastmanager/content/LocalBroadcastManager) is deprecated. You shouldn't be building anything with it. – ianhanniballake Mar 22 '21 at 04:59
  • @ianhanniballake if you convert your comment to an answer, I'll accept it – Maksim Dmitriev Mar 28 '21 at 12:25

1 Answers1

1

Note that LocalBroadcastManager has been deprecated for some time now. This means that it is no longer a recommended solution for anything, including communicating between fragments.

It should also be noted that LocalBroadcastManager is synchronous communication - it requires the listener to be actively listening when the broadcast is sent. In cases where you are communicating a result to a fragment on the back stack, that fragment on the back stack is stopped and shouldn't be listening at all until you return to that fragment and it is started again. This is something all of the recommended patterns already handle for you.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443