Going Two Activities back?

Viewed 17426

I have this Activities sequence: Avtivity01 => Avtivity02 => Avtivity03

You can go from Avtivity01 to Avtivity02 after you click a button.

You can go from Avtivity02 to Avtivity03 after you click a button.

-

I want to go from Activity03 to Activity01 DIRECTLY after I click a button.

-

NOTE:

I do NOT want to use Intent, because I want to have Activity01 as if I pressed the back button from Activity02

How to do that, please?

6 Answers

I was had the same problem,

Short answer is add this line to intent.

intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

Long answer is:

I have MainActivity, SecondActivity and ThirdActivity what i want to do is opening SecondActivity from MainActivity and then ThirdActivity from SecondActivity and i want to click a button in the ThirdActivity that close both of SecondActivity and ThirdActivity without calling a new MainActivity i want it to functional as i back to it not creating a new one And the most thing i need is to keep back button functional normal in the ThirdActivity to back to SecondActivity if i need to change some of my choices in the SecondActivity so i can't call finish(); in the SecondActivity after starting ThirdActivity or any other solutions like android:noHistory="true" in the SecondActivity manifest because those solutions kill the SecondActivity and i can't go back to it throw back button.

so this flag solve the problem for me FLAG_ACTIVITY_REORDER_TO_FRONT

FLAG_ACTIVITY_REORDER_TO_FRONT

If set in an Intent passed to Context.startActivity(), this flag will cause the >launched activity to be brought to the front of its task's history stack if it >is already running.

go to reference here

so i tried this code to go back my MainActivity from ThirdActivity when i click the button in ThirdActivity . i hope this will help you.

Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
Related