I want to show or hide the back button of the action bar depending on the current backstack entry count. That means I want to show it when there is a fragment (or more) in the backstack, and hide when backstack is empty
getSupportActionBar().setDisplayHomeAsUpEnabled(b);
The problem is, when I start a new fragment and ask for the current backstack entry count, it's still the same like before. It refreshes after some milliseconds.
Also in the started fragment's onResume method, the replaced fragment still can not be found in backstack, backstack count is still the same.
Currently I have an AsyncTask that refreshes the button after 50 milliseconds. Working, but this can't be a good solution.
Any ideas?
Best regards
Edit:
Solution was
fragmentManager.addOnBackStackChangedListener(...)