I have an AlertActivity
and an Activity
. When a broadcast is received, both activities needs to finish. But the below code results Black screen if AlertActivity
is on top of Activity
.
Below is the code in Activity
:
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("BROADCAST_INTENT")){
if(alertActvity != null)
alertActivity.finish();
finish();
}
}
And code in AlertActivity
:
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("BROADCAST_INTENT"))
finish();
}
}
First, Activity's onStop()
is getting called before AlertActivity
's onStop()
is called which results in Black screen, even AlertActivity
's finish()
called before Activity
's finish()
.
Please help me in this regard.
Finally, I found a solution for this:
Finishing an Activity
with a delay of 1 second which really works. By that time, AlertActivity
finishes and black screen cannot be displayed.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
finish();
}
}, 1000);
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