I've added custom keyboard to my Fragment and now I want to implement closing keyboard when on back pressed.
class CustomKeyboard
{
public void init(Context context) {
//...
FragmentManager fragmentManager = ((Activity) context).getFragmentManager();
boolean fragmentPopped = fragmentManager.popBackStackImmediate(TAG, 0);
if (!fragmentPopped) {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.addToBackStack(TAG);
fragmentTransaction.commit();
}
}
}
The problem is init
calls every time when screen rotated because I create CustomKeyboard in public void onActivityCreated(final Bundle savedInstanceState)
fragmentPopped=false
every time, so CustomKeyboard may be added to BackStack more than one time.
My question:
Is it possible to add BackStackEntry to BackStack if not exists without using
getBackStackEntryCount()
method?