Search code examples
androidandroid-theme

Switching Themes drops focus for activity on Android 6


Has anyone ever experienced a scenario where you use the AppCompatDelegate to change the theme, then if you hit the back button to go to a previous activity, that activity can not be interacted with. I see the following errors when I tap

Dropping event due to no window focus: MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=245.0, y[0]=928.9525, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=80728630, downTime=80727874, deviceId=15, source=0x1002 }

Any time I try to interact with the screen I get this. If I switch apps, turn the screen off/on, or anything that would cause it to get focus again it's fine.

My exact scenario is that I have an Activity I'm using. I decide to change theme so I go into a settings menu and change them. I then hit back to get out of the settings to my original activity. After I change the theme I can interact in the settings activity. It's only once I leave settings with the back button that I lose the ability to interact.

NOTE: Modern Android 10 devices do not have this issue, only my older Android 6.0.1 devices do.


Solution

  • There is a new version of appcompat available that should solve your issue, 1.2.0-beta01. It looks like in version alpha03 they solved this issue:

    Fix issue where stopped Activities were not resuming on API Level 23 and below (I45201)

    You can find more details on the appcompat releases page.

    Update your build.gradle file to have the following library reference and you should be good to go:

    implementation 'androidx.appcompat:appcompat:1.2.0-beta01'