I am creating a android app where i need to put back navigation ,so that when user click on action bar's home button user should be moved to one screen back on my app.But action bar home button is not responding to click events. Here is my code.
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
ActionBar actionBar = getActivity().getActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
return rootView;
} }
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.home:
Toast.makeText(getApplication(), "Back", Toast.LENGTH_LONG).show();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
Force Restart the Device It fixes all the glitches which can possibly lead to issues like these. For this, hold down your smartphone's power button for 7-10 seconds. After the phone restarts, the home and the back button on your Android phone should work just fine.
case android.R.id.home:
try to use this instead of case R.id.home:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With