Going Two Activities back?
Why can't you use an Intent
? You can use the FLAG_ACTIVITY_CLEAR_TOP when you click the button. Edit: If you want to preserve the original instance of the Activity
, you can use this flag in conjunction with FLAG_ACTIVITY_SINGLE_TOP.
Do you ever want to be able to press a button from Activity03 to go back to Activity02? If you ALWAYS want it to go back to Activity01, you could alternatively use android:noHistory="true"
on Activity02 in the manifest and just call finish()
on Activity03.
link has good article. This will help you. By the way you can use FLAG_ACTIVITY_REORDER_TO_FRONT to solve your problem.
You can go back more than one screen to which ever screen you need using intent and use flags to prevent going back to same screen :
Intent gotoScreenVar = new Intent(goFromScreenCls.this, goToScreenCls.class);
gotoScreenVar.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(gotoScreenVar);
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);