I've a simple Main Activity which has to stop till an SMS is received... How can I launch a method from the MainActivity
within the BroadcastReceiver
's onReceive()
Method?
Is there away with Signal and Wait? Can I pass something with a pending Intent
, or how can I implement this communication?
The problem with registering a second receiver within the activity, however, is that it will not be persistent like registering in the manifest... thus, although, this solution may work, will only work if the activity is running in background.
I had the exact same problem, I tried using intent but i was unsuccessful
The easiest way to use it would be using static methods and static variables
MainActivity.java
SMSReceiver.java
at the end call this function
It works amazing if your code does not affect when you use static methods and variables. Let me know if you need any help.
Communication from BroadcastReceiver to Activity is touchy; what if the activity is already gone?
If I were you I'd set up a new BroadcastReceiver inside the Activity, which would receive a CLOSE message:
Then from the SMS BroadcastReceiver you can send out this action:
I hope this helps?
it's easy, use interface like that:
1) in your broadcast receiver create an interface.
and instantiate that interface in your broadcast receiver, use it:
And in your activity, make it implements your interface