Due to the complex relationship between BroadcastReceiver
, Fragment
and Activity
, I ran into a similar problem and decided to slip out of this rotation and used the following:
When the BroadcastReceiver
onReceive()
method receives a call, add boolean
to SharedPreferences
as an indication indicator that the Fragment should do something, and in the onResume()
fragment method, execute the necessary logic based on the SharedPreferences
boolean
set in the BroadcastReceiver
onReceive()
method.
Remember that there are more effective methods, and that I have not tested this approach in a long-term application.
source share