1

I need to control the back Button event inside fragment code.

The situation is this:

Inside my fragment i have a sliding panel. When the user tap the back Button, if the panel is expanded, I need to close it. If the panel is already close, I need to use my default onBackPressed (in the activity) that launch the popBackStack() method.

Any advice?

My activity onBackPressed.

@Override
public void onBackPressed() {
    if (getFragmentManager().getBackStackEntryCount() == 1) {
        finish();
    } else {
        // super.onBackPressed();
        getFragmentManager().popBackStack();
    }
}
Andres Cárdenas
  • 720
  • 1
  • 5
  • 26

2 Answers2

0

You just need to add testing whether open or closed panel and accordingly perform the desired action.

Miki Franko
  • 687
  • 3
  • 7
0

Keep a boolean value in SettingPrefences whether the panel is expaned or not and then by getting the preffrence value you can manage your backStack

Anuj
  • 402
  • 8
  • 16