质朴的机器人活动的行为,当屏幕关闭? [英] Funky android activity behavior when screen turns off?

查看:125
本文介绍了质朴的机器人活动的行为,当屏幕关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一些有趣的活动流程,当机器人自动关闭屏幕和锁屏......我的应用程序经过正规流程,的onCreate,ONSTART和onResume。然后,我让我的手机坐在那里。当屏幕变黑,在onPause被调用。没关系。然后,5秒钟后,该应用程序被杀死(的onStop,的onDestroy)。那也没关系。但是的马上的的onDestroy被称为后的onCreate,ONSTART和onResume被称为,重新启动,即使屏幕是空白的应用程序。该应用程序有一个加载时间,并播放声音在启动时,所以它是一种令人毛骨悚然,当在30秒前放下手机开始播放声音。为什么要杀的Andr​​oid应用程序,然后重新启动它?目标是2.1更新,而手机是三星的Captivate。任何人看到这一点,知道的方式来阻止它?

I'm seeing some interesting activity flow when android turns off the screen and locks the screen... my app goes through the regular flow, onCreate, onStart and onResume. Then, I let my phone sit there. When the screen goes black, onPause is called. That's fine. Then 5 seconds later, the app is killed (onStop, onDestroy). That's fine too. But immediately after onDestroy is called, onCreate, onStart and onResume are called, restarting the app even though the screen is blank. The app has a load time, and it plays a sound when it starts, so it's kind of creepy when the phone you set down 30 seconds ago starts playing sounds. Why does android kill the app then restart it? Target is 2.1-update, and the phone is a Samsung Captivate. Anyone else seeing this, and know a way to stop it?

推荐答案

在活动的清单,为每个应用程序添加:

In the activity's manifest, for each application add:

android:configChanges="orientation|keyboardHidden"

这告诉你的android会处理这两种情况下自己 - 当然,虽然你在撒谎:你不会做狗屎来处理它们,但Android不知道。这对于应用程序/游戏/等运行,例如在横向模式下,从来没有改变方向的伟大工程。

This tells android you'll handle these two cases yourself - although of course you're lying: you won't do shit to handle them, but Android doesn't know that. This works great for apps/games/etc running for example in landscape mode and never change orientation.

这篇关于质朴的机器人活动的行为,当屏幕关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆