Unable to close all activities on android eclipse

后端 未结 4 1977
眼角桃花
眼角桃花 2020-12-06 09:06

Assume i have four classes.Each class is having a button to do screen switching from one page to another page,well its working fine.But now im trying to close all the activi

4条回答
  •  天涯浪人
    2020-12-06 09:27

    I would insist to create an BaseActivity with a BroadCastReceiver that will notify when you want to finish all the Activities and extend all the Activity classes with this BaseActivity,

    public static final String ACTION_FINISH = "ACTION_FINISH";
    public class BaseActivity extends Activity {
    
    public void onCreate(Bundle bundle, int resourceId) {
        super.onCreate(bundle);
        registerReceiver(finishActivitiesReceiver, 
                                              new IntentFilter(ACTION_FINISH));
    }
    
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(finishActivitiesReceiver);
    }
    
    BroadcastReceiver finishActivitiesReceiver = new BroadcastReceiver() {
    
            @Override
            public void onReceive(Context context, Intent intent) {
                finish();
            }
        };
    }
    

    Then you can just send BroadCast when you want to close all Activities using

    sendBroadcast(new Intent(BaseActivity.ACTION_FINISH));
    

提交回复
热议问题