I\'m working on this project in Android in which an aspect requires a CountdownTimer with a foreground service. A few other answers on Stack Overflow mentioned that LocalBroadca
In addition to "Ryan M" answer, starting with "Fragment" library v1.3.0-alph04 Androidx introduced new "Fragment result Api" which could be used for communication between pair of Fragments or Activity-Fragment. You pass a data/event with a key to a FragmentManager
and a Fragment/Activity having access to that FragmentManager
, can listen to data with specifying proper key.
It might be more suitable than LiveData
to "event"s, but one problem I faced when using it was that you must know the relation between source, target and the FragmentManager
. For example let's assume we are using navigation component from Jetpack, and have a simple fragment witch want to communicate with host Activity. You might think that Activity's supportFragmentManager
and Fragment fragmentManager
are the same instance, but actually there's a NavHostFragment
between theme which have a fragmentManager that host the target activity.