I think this question was asked many times, but no other question somehow answers my issue. The problem is very simple. I have an activity with fragments
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_tabbed);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
}
private void setupViewPager(ViewPager viewPager) {
adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new Fragment1(), "1");
adapter.addFragment(new Fragment2(), "2");
adapter.addFragment(new Fragment3(), "3");
viewPager.setAdapter(adapter);
}
so far so good, I can navigate to fragment 2 and there I can start a new activity
Intent intent = new Intent(activity, AnotherActivity.class);
startActivity(intent);
Then, when I finish doing stuff in this anotheractivity, can use the back button to return to my activity with fragments. But then, it always starts with fragment1 instead of fragment2, the one I started the anotheractivity. How can I make it return to the original state with fragment2 active?
I tried onSaveStateInstance and PendingActivity, but both in vain.