Muhammad Abdullah
Muhammad Abdullah

Reputation: 137

How to go back to the fragment in an activity which launched the activity?

If i have 4 fragments in my main activity .. if i launch an activity from any one of them. Then how do i go back to that last fragment from the new activity ? E.g Activity A has 1 2 3 and 4 fragment. i launch Activity B from fragment 3. now i want to go back to Activity A but in fragment 4 .. if i just use finish() activity or the the home button in appbar .. i goto to Activity A fragment 1.. but i want it to be Activity A fragment 3.. Any help ? i want that back arrow in the appbar to accomplish this functionality ? or when in any case im done with this activity ?

Upvotes: 0

Views: 42

Answers (2)

David Wasser
David Wasser

Reputation: 95578

Just calling finish() or using the BACK button should return you to the previous Activity in the state it was when you left it.

Upvotes: 1

Ahmed AlAskalany
Ahmed AlAskalany

Reputation: 1610

Call transaction.addToBackstack(null) before committing your fragments transactions.

Upvotes: 0

Related Questions