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(...)
答案 0 :(得分:1)
AsyncTask
您没有必要在添加或删除片段Backstack
时触发onBackStackChangeListener
接口,而不是您的调用工具并调用{{1}如果它不是0那么你就知道你会做什么
母鸡,我开始一个新的片段,并要求当前的后台进入计数,它仍然像以前一样
您需要在getBackstackEntryCount()
或Backstack
之后add()
拨打replace()
FragmentTransaction
之后将您的交易添加到.addToBackstack("the identifier")
希望有所帮助