onDestroy() 在 this.finish() 之后不会被调用
我想知道为什么带有 2.1-update1 的 Motorola Milestone 的行为与模拟器或 Nexus One 不同。我正在尝试通过以下方式退出我的应用程序:
@Override
protected void onPause() {
if(mayDestroyActivity) this.finish();
super.onPause();
}
这在模拟器或 Nexus One 上运行良好。 onDestroy()
在 onPause()
和 onStop
之后立即调用。但不适用于里程碑。相反,当另一个 Activity 启动时,onDestroy()
会被调用。它在清单中的部分如下所示:
<activity android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/questionnaire_item"
android:launchMode="singleInstance"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<category android:name="android.intent.category.OPENABLE" />
</intent-filter>
</activity>
有人对此有提示吗?我的应用程序依赖于正确退出,因为我在 onDestroy()
中保存了所有进度,
谢谢,
斯特夫
I'm wondering why the Motorola Milestone with 2.1-update1 behaves differently from the Emulator or e.g. the Nexus One. I am trying to exit my app with:
@Override
protected void onPause() {
if(mayDestroyActivity) this.finish();
super.onPause();
}
This works well on either Emulator or Nexus One. onDestroy()
gets called immediatly after onPause()
and onStop
. But not for the Milestone. Instead, onDestroy()
gets called when another Activity is started. Its section in the Manifest looks like this:
<activity android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/questionnaire_item"
android:launchMode="singleInstance"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<category android:name="android.intent.category.OPENABLE" />
</intent-filter>
</activity>
Does anyone have a hint on this? My app depends on exiting properly since I save all progress in onDestroy()
Thanks,
Steff
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你做错了。这就是医生所说的:
http://developer.android.com/reference/ android/app/Activity.html#onDestroy%28%29
You are doing it wrong. This is what the Doc says:
http://developer.android.com/reference/android/app/Activity.html#onDestroy%28%29
如果用户退出到主屏幕,这并不意味着应用程序应该退出。在大多数情况下,如果应用程序只是转到后台,则会提供更好的用户体验。尝试依赖 saveInstanceState 和 onPause。
在 Android 世界中,退出应用程序被视为不好的做法,如果应用程序在按下主屏幕后继续运行,则具有良好的真正多点触控系统的手机可以获得更好的用户体验。
If the user exits to the home screen this does not need to mean that the app should be exited. In most of the time it will give a better user experience if the app just goes to the background. Try to rely on saveInstanceState and onPause.
Exiting a app is seen as bad practice in the android world, featuring a phone with a good system for true multitouch can get better user experience if the app keeps running after pressing the home screen.
您应该使用
onSaveInstanceState
,检查这个 链接。You should use
onSaveInstanceState
, check this link.