Create a new parent class, dynamically register the broadcast in the parent class, end the current activity in this broadcast's Onrecive method, let each activity inherit the parent class, send the broadcast in the activity to be closed, fix
Here is the code
Parent class
protectedmyrecive myrecive; Private classMyreciveextendsbroadcastreceiver{@Override Public voidOnReceive (Context context, Intent Intent) {LOG.V ("SK", Getlocalclassname ()); Finish (); }} @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.LAYOUT.ACTIVITY_MAIN_ACTIVITY4); Myrecive=Newmyrecive (); Intentfilter _filter=NewIntentfilter (); _filter.addaction ("Com.xl.u323"); Registerreceiver (Myrecive,_filter); }
End method
Public void OnClick (View v) { new Intent (); _intent.setaction ("com.xl.u323"); Sendbroadcast (_intent);}
Use a broadcast to exit a program that has multiple activity open