I am using a reciever class defined in the manifest like
<receiver
android:name="com.escortme.basic.SMSReceiverActivity"
android:enabled="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
to listen on incoming texts, but the problem is how do I call a method which is the current activity that the phone is showing, from the onrecieve method in SMSReceiverActivity ?
So for example, if I am currently on pol_viewactivity on my phone, then i recieve a text, i know that the onrecieve method occured in the background from SMSReceiverActivity, but in the onreceive method, how do I call a method back from pol_viewactivity?
Then you should either
1) put your
onReceivemethod in yourpol_viewactivity; or,2) provide a listener in
SMSReceiverActivityand set bypol_viewactivity.EDITED:
In response to how to create a listener.
In your
SMSReceiverActivity, define an interface,declare the listener and a public method,
In the
onReceivemethod of theBroadcastReceiver,In your
pol_viewactivity, find ways to set the listener similar to the way of callingsetOnClickListener(). If you cannot retrieve the instance of theSMSReceiverActivityin order to set the listener, then make the listener static. I know this is not a beautiful way to do so, but in your case, if you can’t change the design, this way should help. (Perhaps you can isolate the BroadcastReceiver into a single class and do all the handling there.)