Search code examples
androidbroadcastreceiver

How do I get information from the main activity into a broadcast reciever?


I have a broadcast receiver that will receive some sms messages. I am planning on filtering out who's sms's I will react to based on some data in the main activity. How do I get this data into the broadcast receiver? I was thinking I could call a method on the main activity in the onReceive in the receiver, but what happens if the activity is paused or stopped? Is the only option to read the info from persistent storage, like the shared preferences file?


Solution

  • Yes, you should read the Data into Persistent state, in that case your received values from Broadcast receiver will be accessed every time when your Activity's onResume or onCreate is called. (It depends on you how do you manage it)