Search code examples
androidandroid-activityandroid-edittextactivitygroup

Child activity from ActivityGroup just "sometimes" calling onBackPressed()


I have an ActivityGroup with several child Activities.

Recently I discovered that the onBackPressed method is not always being called on the child Activities but in the parent Activity (the activityGroup).

After some testing I discovered that the onBackPressed is only invoked on the children when they have a focused EditText. If the EditText is not focused or if there is no EditText (even if there are other controls such as buttons or checkboxes) then it won't be called after all.

If the child receives this invocation, then the parent doesn't.

Does anyone know why the behavior of the Activity changes? Is there some method I can execute on the child Activity so that it always gains this focus and gains the onBackPressed method preference?


Solution

  • Well the easiest implementation was to create a method that was called either by the parent->currentChild or by the child when the back button was pressed.