标签:
新建一个父类,在父类里动态注册广播,在这个广播的onrecive方法中结束当前activity,让每个activity继承这个父类,在要关闭的activity中发送广播,搞定
下面是代码
父类
protected Myrecive myrecive; private class Myrecive extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { Log.v("sk",getLocalClassName()); finish(); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_activity4); myrecive = new Myrecive(); IntentFilter _filter = new IntentFilter(); _filter.addAction("com.xl.u323"); registerReceiver(myrecive,_filter); }
结束方法
public void onClick(View v) { Intent _intent = new Intent(); _intent.setAction("com.xl.u323"); sendBroadcast(_intent); }
标签:
原文地址:http://www.cnblogs.com/u3shadow/p/4316939.html