I have an Activity
and it has only one Fragment
. I want to handle backpressed
functionality. When user presses back, program should go back to Activity
. I know this is very simple but I have tried some solutions that are mentioned on Stackoverflow, but none of them worked. For example I tried this:
public void onBackPressed() {
int count = getFragmentManager().getBackStackEntryCount();
if (count == 0) {
super.onBackPressed();
//additional code
} else {
getFragmentManager().popBackStack();
}
}