1

So I have an app with just a few Activities and many fragments that are being replaced into the MainActivity layout. This is pretty straight forward.

 FragmentManager fragmentManager = fragment.getFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); MyFragment f = MyFragment.newInstance(); transaction.replace(R.id.container, f); transaction.addToBackStack(null); transaction.commit(); 

When MainActivity extends Activity, everything works just fine. But I changed this to ActionBarActivity, in order to implement Toolbar, and suddenly the backstack does Activities only.

The strange thing is, on Android 4.x it still works. On 5.x, the Fragments are skipped.

Any ideas?

1 Answer 1

2

ActionBarActivity is part of the support library, so you need to use getSupportFragmentManager(), not getFragmentManager().

Sign up to request clarification or add additional context in comments.

1 Comment

And just a heads up that ActionBarActivity is now deprecated, worthwhile updating to use AppCompatActivity when you can.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.