Android的锁屏启动应用程序后重新启动

Android的锁屏启动应用程序后重新启动

问题描述:

我一直在玩的状态,整天试图找出为什么,当我preSS的电源按钮,打开锁屏,我的应用程序失去焦点,并调用它的onStop()(因为它应该),但然后它调用ONSTART()之前再次兴田屏幕熄灭。这引起了我一个问题,因为在我的应用程序的一些声音(和presumably其他的东西)重新开始播放,而锁屏被激活。

I have been playing with the states all day trying to figure out why, when I press the power button to bring up the lock screen, my app loses focus and calls it's onStop() (as it should) but then it calls the onStart() again before hte screen goes off. This is causing me a problem because some sounds in my app (and presumably other stuff) start playing again while the lockscreen is active.

如何才能确保它是正确中背景和停止时,锁屏被激活?

how can I make sure it is properly backgrounded and stopped when the lockscreen is active?

我不久前面对这个确切的问题。在AndroidManifest.xml中,请确保您有这样的:

I faced this exact problem not long ago. In AndroidManifest.xml, make sure you have this:

安卓configChanges =keyboardHidden |定位

android:configChanges="keyboardHidden|orientation"

这将prevent再次启动,在运行配置更改你的活动。 See处理配置改变自己。这样,你的应用程序将监听事件会导致重新启动 - 样的方向和键盘的可见性的变化 - 和你的活动范围内处理它们

This will prevent your activity from being restarted on runtime 'configuration changes'. See handling the configuration change yourself. That way your app will listen for events that would cause a restart - like orientation and keyboard visibility changes -- and handle them within your Activity.

还有上所以这里一个非常类似的问题: 在旋转的Andr​​oid 活动启动

There is also a very similar question on SO here: Activity restart on rotation Android