简体   繁体   中英

How to finish an activity but I don't want go to previous activity (goto another activity)

Let say there is an activity stack A -> B -> C -> D, from activity D, I want to finish it and go to activity A. It's ok to destroy activity B and C, btw. activity D can be accessed from activity A / B / C. So If I call activity D from B (A -> B -> D), I still want to go to activity A.

In Activity D:

Intent intent = new Intent(ActivityD.this, ActivityA.class);
                intent.putExtra("param", param); //optional
                startActivity(intent);
                finish();

Do like this:-

Call the Intent on the onBackpressd() method.It will go on that activity which you want. Like:-

 @Override
    public void onBackpressd() {
        super.onBackpressd();
       Intent intent = new Intent(ActivityD.this, ActivityA.class);
                    intent.putExtra("param", param); //optional
                    startActivity(intent);
                    finish();
    }

Hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM