Android的activity.onPause(),然后activity.onResume()重新启动应用程序 [英] Android activity.onPause() then activity.onResume() restarts the app
问题描述
我可以成功调用activity.onPause()暂停应用程序。
但是,当我打电话activity.onResume()的应用程序重新启动。
I can successfully call activity.onPause() to pause the application. But when i call activity.onResume() the application restarts.
有没有办法避免这种情况?
Is there a way to avoid this ?
编辑
其实我是想用一个暂停按钮暂停我的应用
I actually want to pause my application using a pause button
推荐答案
您永远不应该叫活动的方法
自己的生命周期!因此没有呼叫的onPause()
onResume()
的onDestroy()
的onCreate()
的onStop()
或在onStart()
。
You should never call methods of the Activity
life cycle by yourself! So no call to onPause()
onResume()
onDestroy()
onCreate()
onStop()
or onStart()
.
编辑以满足您的编辑问题:
Edit to fit your edited question:
您应该暂停比赛,而不是活动。您必须在您工作时的游戏逻辑线程。这线程需要被暂停,而不是游戏。因此,考虑暂停逻辑有工作。
You should pause your game, not the Activity. You must have a thread where you work your game logic. That thread needs to be paused, not the game. So consider working on a pause logic there.
这篇关于Android的activity.onPause(),然后activity.onResume()重新启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!