When to call SDL_StopTextInput

I’m doing text editing in a game to enter character names, etc. I am
calling SDL_StopTextInput() when the user presses either Return or Escape.
That usually works fine, except that on Android, there are other ways that
the OS signals that the user is done with the soft keyboard. When one of
those signals happens, my game can’t respond appropriately because there is
no notification that text editing should end.

I can mess with the Java code to send Enter and Escape keycodes when
Android wants to hide the soft keyboard, but is there a better way to
communicate this with my game?

Jonny D