0

i have 2 activity Activity-1 and Activity-2 ..... Activity-2 has fragments fragment-1 and fragment-2 and fragment-3 The work flow is.. Activity 1 ---> Activity 2---> fragment 1 ---> fragment 2 ---> fragment --->3 but i am trying back the following sequence.. fragment 3 ---> fragment 2 ---> fragment --->1 Activity 2 ---> Activity 1

i have used

ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

it shows an back button left of the ActionBarActivity

i can get the click event here...

public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            //do your own thing here

            return true;
        default: return super.onOptionsItemSelected(item);  
        }
    }

what should i do ?????

3 Answers3

1

When applying your fragment transactions, you need to make sure they are added to the fragment back stack with the addToBackStack() method. Then the framework will do the work of unwinding the fragments before finishing the host activity.

You can read more in the Fragments Developer Guide.

devunwired
  • 62,780
  • 12
  • 127
  • 139
1
popBackStack and addToBackStack methods will do. See links for details:

How to resume Fragment from BackStack if exists http://developer.android.com/training/implementing-navigation/temporal.html

Community
  • 1
  • 1
Shubham
  • 2,627
  • 3
  • 20
  • 36
1

You need to use addtoBackStack to add a fragment to backstack, for activity that will be done by default and not for fragments. See the video in the following link. You will get the complete picture:

https://www.youtube.com/watch?v=ZbKKxYUOH-c&list=PLonJJ3BVjZW4lMlpHgL7UNQSGMERcDzHo

keshav kowshik
  • 2,354
  • 4
  • 22
  • 45