I've gotten two issues recently which I suspect are related to the same fact.
The first problem: I noticed none of my EditTexts were pulling up the soft input keyboard (they always did previously), and, to test it out, I created an entirely new "default" (no custom changes) EditText and still, although the view got focus (the cursor appeared and all), the leyboard still didn't show up. Manually calling InputMethodManager.showSoftInput()
returns false too. The issue is weird because, when I call activity.getCurrentFocus()
, I receive exactly the EditText view I was expecting, but calling editText.hasWindowFocus()
returns false (and having window focus is a requirement for showing the IME according to documentation).
The second problem: onBackPressed()
is never fired in any of my activities. Whether the system bars are hidden or not, or whether the back event is generated by a button or a gesture, they never get fired, which, due to the issue with the EditTexts, makes me suspect it's related to the fact my windows don't have focus.
Finding out what's wrong: I couldn't find any singular code changes I made that could impact the app in such a way, except maybe changing targetSdk
to a level higher than my development device, but I changed it back to API 31 (my device) and no changes were made. I also tested if the issue was perhaps with my device, but deploying the app on another tablet produced the same issues. I have also thoroughly checked my manifest for potential sources of the problem, but nothing found. Is there usually a reason for why an activity's window loses focus, and a way to manually set it?
Okay I just found the issue. I was calling Window.setFlags(Window.FEATURE_ACTIVITY_TRANSITIONS, Window.FEATURE_ACTIVITY_TRANSITIONS)
on the startup of all my activities, and, for some reason I'm yet to learn, it messed up the window focus completely. Everything works fine now though, I will edit this answer if I find the reason.