由于没有窗口焦点而导致Android错误取消事件 [英] Android Error Cancelling event due to no window focus
问题描述
我正在学习Android,并尝试制作多屏应用以使其更胜一筹.我有3个活动.
I am learning Android, and trying to make multi screen app to get better at it. I have 3 activities.
1) Main
2) Game
3) GameOver
主机具有游戏按钮,按下该按钮可启动游戏活动的意图.在计时器中的计时器结束后,我将意图的得分变量传递给GameOver Activity. 此流程工作正常.但是当我看到GameOver激活结果后按返回按钮时,该应用程序将最小化.当我取消最小化应用程序时,它会显示主要活动"屏幕(实际上是想要的,但没有最小化应用程序).我在Game Activity中使用finish(),在其中我为GameOver调用Intent.
Main has game button, when pressed starts intent for the Game Activity. And after timer finishes in Game, I pass score variables to GameOver Activity over intent. This flow works fine. But when I press back button after I see results in GameOver activit, the app minimizes. When I unMinimize the app it shows the Main activity screen (which actually want, but without app getting minimized). I am using finish() in Game activity where I am calling intent for GameOver.
在日志中,出现以下错误:
In logs, I am getting following errors:
D/OpenGLRenderer: endAllActiveAnimators on 0xb7d6e128 (RippleDrawable) with handle 0xb7877690
W/ViewRootImpl: Cancelling event due to no window focus: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x68, repeatCount=0, eventTime=292244107, downTime=292244100, deviceId=-1, source=0x101 }
我创建了一个测试应用程序来解决/理解具有3个活动和相同流程的此问题.在该基本活动应用中可以正常工作.但不在我的主应用程序中.我搜索发现它不是错误.没关系,但是我不希望按下后退按钮时我的应用程序最小化.有帮助吗?
I created a test app to resolve/understand this issue having 3 activities and same flow. It is working find in that basic activity app. But not in my main app. I searched and found that its not an error. That's okay but I don't want my app to get minimized when back button is pressed. Any help?
推荐答案
从MainActivity中删除 finish(). (如果您有意在其中进行游戏活动",则为该人.)
Remove finish() from MainActivity. (If you have one at the intent where you call for Game Activity.)
这篇关于由于没有窗口焦点而导致Android错误取消事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!