简体   繁体   English

android休眠杀死该应用程序-onDestroy

[英]android hibernation kill the app - onDestroy

I'm developing with API level 8 on android 2.2 我正在使用Android 2.2上的API级别8进行开发

I read this about the life cycle of an android app : http://developer.android.com/reference/android/app/Activity.html but there is no comments about the hibernation state and how to handle it correctly... 我读到了有关Android应用程序生命周期的信息: http : //developer.android.com/reference/android/app/Activity.html,但没有关于休眠状态以及如何正确处理休眠状态的评论...

when I switch off the device (and when my app is still running) the os calls the onDestroy method... and when I switch on the device my app start from the beginning, the os calls the onCreate method... 当我关闭设备(并且我的应用程序仍在运行时)时,操作系统会调用onDestroy方法...而当我打开设备时,我的应用程序将从头开始,则操作系统会调用onCreate方法...

it could be better that the os calls only the onPause / onResume on hibernation, no ? 操作系统在休眠状态下仅调用onPause / onResume会更好,不是吗?

I look about Angry Birds on android and it is still living when the device switch on, they don't reload textures or anything else like one instant... 我在android上看到《愤怒的小鸟》,当设备开启时它仍然存在,它们不会重新加载纹理或其他任何类似的东西...

so how to do the same ? 那么该怎么做呢? :) :)

you would need a partial wake lock , so that your application would continue to run even when the screen is switched off. 您将需要部分唤醒锁 ,以便即使关闭屏幕,您的应用程序也可以继续运行。 In a partial wake lock, the CPU is not put to sleep and only the screen is dimmed. 在部分唤醒锁定中,CPU不会进入睡眠状态,只有屏幕变暗。 I think this is what the Angry Birds game does. 我认为这就是《愤怒的小鸟》游戏所做的。 http://developer.android.com/reference/android/os/PowerManager.WakeLock.html http://developer.android.com/reference/android/os/PowerManager.WakeLock.html

add in the manifest xml file : 添加清单xml文件:

  • android:launchMode="singleTask" android:launchMode =“ singleTask”
  • android:configChanges="keyboardHidden|orientation" android:configChanges =“ keyboardHidden | orientation”

thx to Chris & to all 克里斯和所有人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM