Finish All Instance of particular Activity

杀马特。学长 韩版系。学妹 提交于 2019-12-05 07:46:26

I don't know a way to close activity C1 manually when finishing activity C2.

However you can take care of activity C1 in it's on resume this way -

1 - Set a flag in your application class :

public static boolean IsClosingActivities = false;

This value can be set "true" by C2 right before "finish" of activity C2 occurs.

And set "false" in the point where you'll call startActivity for a new activity C. (Assuming that new instances of activity C can be created later in the application).

2 - In C implementation of on resume :

    @Override
    protected void onResume() {     
        super.onResume();
        if (YourApplication.IsClosingActivities) {
                this.finish();
        } 
    }

This way - when the user navigates back from D - C1 will finish itself and he will be navigated to B.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!