i have one activity Main.java is open in my application, i want to close the activity using broadcast receiver , how to close the activity?
Firstly your Main.java needs to be registered as a receiver. You could register it in Main.java's onResume():
@Override
public void onResume() {
registerReceiver(broadcastReceiver, new IntentFilter(BroadcasterClassName.NAME_OF_ACTION));
}
Then handle the broadcast and finish your activity:
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(BroadcasterClassName.NAME_OF_ACTION)) {
finish();
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With