Fix ToolBar Navigation Back Button not Working Issue in Android Java

Android Fix HomeAsUp Button Not Working Error in Java

I experienced this error when i created a SettingsActivity for my app. I think the cause of this error was that i forgot to define a parentActivity while creating the SettingsActivity. The parent activity must defined because this is the activity where the app goes back when the HomeAsUp Button is clicked.

There are two ways to fix this, one easy way is by going to the manifest file and add this line of code in the activity name:


The second way is adding this code below the oncreate method:

ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } }

@Override public boolean onSupportNavigateUp() { 
return true; }
, ,

Post navigation


This site uses Akismet to reduce spam. Learn how your comment data is processed.