I have a typical application. An activity which has a FrameLayout and in this layout I want to switch between fragments. This is typically and easily done with:
getFragmentManager().beginTransaction()
.replace(R.id.ac_container, new FrOverview())
.addToBackStack(null)
.commit();
The problem is, that even if I use .addToBackStack(null)
(And I know it's been added 'cause the stack count increases) when I press back I exit the application. I have been trying a lot of different code stuff and checked most threads here on Stackoverflow but I can't get it to work with code (method calls etc.).
But! I can get it to work, by changing the extended class of my activity class. If my class extends Activity
, it works fine. But if I use AppCompatActivity
(which in turn extends FragmentActivity
) then it has the bad behaviour as explained earlier.
Feels like this has to be an error on Androids part, I am not doing anything wrong to my knowledge.
Does anyone have any suggestions on how to solve this? i.e. get the back functionality and keep the ActionBar!
AppCompatActivity
uses the SupportFragmentManager
, you need
to switch to SupportFragment and SupportFragmentManager
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With