0

I have four fragments in one viewpager of Activity1, In any of fragment1~4, I open another activity2 by startactivity(Intent), In activity2, I want to return back to previous fragment or other specified fragments, but Now I always return back to the first fragment1 by startactivity(), Any good ideas ? Thanks

yzycqu
  • 35
  • 4

1 Answers1

0

You can access the current 'page' and set the current page like this. I guess you could bundle this information when you start activity2 through the intent. Note "FirstFragment" is the name of the activity that sets up my view pager etc with fragments.

int currentviewnum =  ((FirstFragment) getActivity()).getPager().getCurrentItem();   

Once, in activity 2 and you want to return back to it, or another view pager (currentviewnum), you could do something like this in an override for the back button (see here for that Android - How To Override the "Back" button so it doesn't Finish() my Activity?); But you can do something like this!

((FirstFragment) getActivity()).getPager().setCurrentItem(currentviewnum);

So effectively when you press the back button, let me know if this works. I do something like this in my app. But instead of going back, it's more to go to the next one!

Community
  • 1
  • 1
Leon92
  • 505
  • 1
  • 9
  • 15