java - ActionBar back button finishing activity from inner Fragment -
i have appcompatactivity actionbar incorporating button. starting inner fragment class opens view on top of activity view. hardware button closes fragment , activity view visible. if press button on actionbar whilst in fragment view, app goes mainactivity, activities parent. want either hide actionbar, or ideally give same behaviour hardware button, annoying behaviour user. have tried creating instance of actionbar in activity, this
actionbar actionbar = getactionbar(); actionbar.sethomeasupenabled(true);
this gives me nullpointerexception
in runtime. have searched , stumped.
also tried this, mfragmentmanager has .addtobackstack() before begins transaction fragment class.
@override public void onbackpressed() { int count = mfragmentmanager.getbackstackentrycount(); if (count == 0) { super.onbackpressed(); //additional code } else { mfragmentmanager.popbackstack(); } log.i(log_tag, "onbackpressed. count = " + count); }
~no errors actionbar button behaviour no changed. no log message recorded~
my mistake, method did change behaviour hardware button. caused nullpointerexception
when trying getbackstackcount()
on mfragmentmanager
.
the action bar "back" button up button, , according google supposed behave differently hardware button: https://developer.android.com/training/design-navigation/ancestral-temporal.html
that being said, can intercept touches on button , whatever want them.
@override public boolean onoptionsitemselected(menuitem item) { if (item.getitemid() == android.r.id.home) { // code here } return super.onoptionsitemselected(item); }
Comments
Post a Comment