Problems With Fragment Onbackpress
in my navigation drawer there are 5 menu items.one of them is about us item.when I click on this item, I call AboutUsFragment and show it(its content is just a text).but when I cli
Solution 1:
used this method instead of onBackPressed
if you have toolbar then here is my solution, type under the oncreate method below toolbar,
assert getSupportActionBar() != null;
// getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
and set this code in your manifest file for your fragment
<activityandroid:name=".yourCurrentFragment"><meta-dataandroid:name="android.support.PARENT_ACTIVITY"android:value=".whichActivityYouWantToGo" /></activity>
Solution 2:
Try this:
@OverridepublicvoidonBackPressed() {
if (getFragmentManager().getBackStackEntryCount() == 0) {
super.onBackPressed();
} else {
getFragmentManager().popBackStack();
}
Post a Comment for "Problems With Fragment Onbackpress"