The text below first was an edit on the question itselve, but because nobody seemed reluctant to answer my question I've added it as an answer so people who have a similar question are maybe helped by this.
If someone has a better answer, I'm still interested in a cleaner solution.
Ok, I managed to solve my own question, but I'm not realy sure I'm satisfied with it. What I did was add a fake entry to the backstack in onCreateActionMode, like so:
@Override
public boolean onCreateActionMode(ActionMode actionmode, Menu menu) {
MenuInflater inflater = actionmode.getMenuInflater();
inflater.inflate(R.menu.task_contextual_menu, menu);
getActivity().getSupportFragmentManager()
.beginTransaction()
.addToBackStack(null)
.add(new Fragment(), FAKE_BACKSTACK_ENTRY)
.commit();
return true;
}
and popping that back off in onDestroyActionMode and instead of checking in onBackPressed for (fragmentManager.getBackStackEntryCount () != 0)
, I check for (fragmentManager.getBackStackEntryCount () == 1)
.
I'm kind of proud of the workaround, but I realise it's not the cleanest of solutions...