You can create a Callback using an interface for calling that the activity method from BroadcastReceiver
interface MyCallback{
public void doStuff();
}
Provide the CallBack in the BroadcastReceiver
public class MyBroadcastReceiver extends BroadcastReceiver{
private MyCallback callback;
public MyBroadcastReceiver(MyCallback callback){
this.callback = callback; //<-- Initialse it
}
@Override
public void onReceive(Context context, Intent intent) {
callback.doStuff(); //<--- Invoke callback method
}
}
Now implement the Callback in your Activity and override the method
MyActvity extends AppcompatActivity implements MyCallback {
// Your Activity related code //
// new MyBroadcastReceiver(this); <-- this is how you create instance
private void sendSMS(){
// your logic to send SMS
}
@Override
public void doStuff(){
sendSMS(); //<--- Call the method to show alert dialog
}
}
You can read the advantage of using this approach here in detail