作者:Scott-Wang
来源:CSDN
原文:https://blog.csdn.net/u012724947/article/details/53808406
通过广播来关闭指定的Activity
setp1:在每个Activity中注册BroadcastReceiver
CloseActivityReceiver closeReceiver = new CloseActivityReceiver();
IntentFilter intentFilter = new IntentFilter("con.lcry.close.activity");
registerReceiver(closeReceiver, intentFilter);
setp2:在当前的Activity中实现内部类,关闭Activity
/**
* 实现Activity的广播接收
* @author LCry
*/
public class CloseActivityReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent){
xxxActivity.this.finish();
}
}
setp3:在需要关闭Activity时发出广播,告诉对方,我要把你结束
Intent intent = new Intent();
intent.setAction("con.lcry.close.activity");
sendBroadcast(intent);