Here again!
The situation is this: I have:
Action A, which implements viewPager and renders 3 possible fragments. To access each fragment, I use this code:
@Override public Fragment getItem(int page) { switch (page) { case 0: return new MyFirstFragment(); case 1: return new MySecondFragment(); case 2: return new MyThirdFragment(); } return null; } @Override public int getCount() { return [the count of total fragments]; }
Fragment 3 contains a list of users. When I click on the user, action B starts. Using the intent:
// Create new Intent Object, and specify class Intent intent = new Intent(); intent.setClass(Fragment3.this, ActivityB.class); //Use startActivity to start Activity B startActivity(intent);
In activity B there is a button that redirects me to fragment 2. So, the question is: how can I return, see fragment number 2? I was thinking about starting A again and using putExtra to indicate which fragment should be rendered.
For example, I would pass the number 2 in this case and would like to call the Fragment getItem (2) function to render the fragment. However, the Fragment getItem is contained in the pageadapter class, so I don't understand how to do this.
source share