I'm working on an app that only uses a single Activity and switches out fragments as they are needed with the navigation drawer. Now we want to navigate back from one of these fragments by using the homeAsUp button in the ActionBar.
I have followed all the steps to set the button up. From disabling the navigation drawer setDrawerIndicatorEnabled(false)
and calling setDisplayHomeAsUpEnabled(true)
in the fragment's onCreateView()
.
I also set setHomeButtonEnabled(true)
in the MainActivity's onCreate()
however because the app is already in the MainActivity, we cannot specify a Parent Activity.
Whenever I run a fresh install of the app, the homeAsUp button works and is registered in the onBackPressed()
, not onOptionsItemSelected()
method. However, when I close the app and run it again the button does not even register clicks.
In onBackPressed()
I check a few conditions, but it does not block the button press.
In onOptionsItemSelected()
I check for android.R.id.home
.
Unfortunately, I cannot post the code.
This post describes what I'm trying to achieve: Switching between Android Navigation Drawer image and Up caret when using fragments