Skip to content Skip to sidebar Skip to footer

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

    <activity android:name=".yourCurrentFragment">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".whichActivityYouWantToGo" />
    </activity>

Solution 2:

Try this:

@Override
public void onBackPressed() {
    if (getFragmentManager().getBackStackEntryCount() == 0) {
        super.onBackPressed();
    } else {
      getFragmentManager().popBackStack();
    }

Post a Comment for "Problems With Fragment OnBackPress"