Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go back to previous screen without creating new instance

Tags:

android

enter image description here

As explained in image, flow is something like this. So whenever user click on logo button Activity A should be called. As simple solution we can use this method...

Intent intent = new Intent(activity, activityToStart);
startActivity(intent);

But this activity will create a new activity for my app. but I need to call the same instance of the activity as we move forward in flow diagram. from Activity A to B and then again on B can be called easily by callingfinish() but from Activity C or D, how to come back to A.

I am running out of ideas but not getting any fruitful result. Please help me if you have any suggestion or at any place i am going wrong. Thanks in advance.

like image 955
Android Avatar asked Jul 30 '12 05:07

Android


People also ask

How do I get my old Android activity back?

In the second activity, the back button at the top left can be used to go back to the previous activity.

Do all Android devices have back button?

All Android devices provide a Back button for this type of navigation, so you should not add a Back button to your app's UI. Depending on the user's Android device, this button might be a physical button or a software button.

How do I move one monitor to another in flutter?

In this Flutter Tutorial, we learned how to navigate between two screens/pages using Navigator. push() and Navigator. pop().


2 Answers

To Come Back from D to A, use Intent Flags.

Intent intent = new Intent(activity, activityToStart);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent);

FLAG_ACTIVITY_CLEAR_TOP, will instead of creating new activity, it will invoke the activity on the stack, and will pop all the activities over the activity being invoked.

like image 77
jeet Avatar answered Sep 22 '22 07:09

jeet


Instead of Using

Intent intent = new Intent(activity, activityToStart);
startActivity(intent);

Use

Intent intent = new Intent(activity, activityToStart);
startActivityforResult(intent,1234);

This will make Sure that The Activity A is not Killed and when You finish Your Activity C,Activity A will get Resumed.

Note :- Whenever You create A new Activity,without finishing(Exiting) the Host Activity,The Host Activity is Saved On the Stack in LIFO order

LIFO:- Last In First Out

like image 31
Haresh Chaudhary Avatar answered Sep 22 '22 07:09

Haresh Chaudhary