Let's see this situation: you've got a CAB open with DONE & DISCARD options on a screen with a form to be filled and you won't accept an error value for a field. Hence, the user should either fill in a valid value (and press Back/Done for it to be accepted) or press Discard on the CAB.
Pressing DONE initiates onDestroyActionMode()
immediately, after which the CAB is closed.
So, this is the place (beside the onBackPressed()
) where the check for validity is initiated.
The problem is, if creating a new ActionMode there (if the form validity check fails), the recursive loop will be started (as the new CAB will first start closing the old one and so on) --> StackOverflowError.
I tried creating a state variable to prevent the StackOverflowError, but in that case it works only every second time (and only onBackPressed()
) :-/
So, the question: how do I keep the CAB open (or how to re-open a new one) immediately after onDestroyActionMode()
was called on it?
The first commenter is indeed correct. Action modes are transient and can be finished by the user at any time by design. They're for representing something like a batch selection that you can add to or remove from before taking an action on the full set, mail triage and text editing being two examples. Finishing an action mode should be non-destructive, just like canceling a dialog. It should not be treated as a confirmation step.
Speaking of text editing, you're heavily implying that your form involved here contains text fields. What happens when a user highlights some text and the TextView starts its own editing action mode? Starting an action mode will implicitly finish any current action mode.
You should use another affordance to express an edit in progress.