Android - 应用程序最小化处理
我不相信这被称为最小化,但基本上当用户离开我的游戏时,有没有一种简单的方法可以暂停它?我唯一知道的是捆绑包,IE RestoreState(Bundle savingState)
问题是,我发现自己尝试解决诸如此类的变量上的各种逻辑问题:
xGrid = new float[savedState.getFloatArray("xGrid").length];
yGrid = new float[savedState.getFloatArray("yGrid").length];
xGrid = savedState.getFloatArray("xGrid");
yGrid = savedState.getFloatArray("yGrid");
是否有更简单的方法,例如停止线程并在它们返回时恢复它?这非常烦人,考虑到我的应用程序仍在开发中,每次添加变量时我都必须更新它。我知道我是一个懒惰的程序员,但是......这就是编程的意义,对吗? (因为懒。)
I don't believe it is called minimization, but basically when the user navigates away from my game, is there an easy way to pause it? The only thing I know of is bundles, IE restoreState(Bundle savedState)
The problem is, I find myself trying to all sorts of logic problems on variables like this:
xGrid = new float[savedState.getFloatArray("xGrid").length];
yGrid = new float[savedState.getFloatArray("yGrid").length];
xGrid = savedState.getFloatArray("xGrid");
yGrid = savedState.getFloatArray("yGrid");
Is there an easier way like just stopping the thread and resuming it when they return? This is awfully annoying, considering my app is still in development and I have to update this every time I add a variable. I know i'm a lazy programmer, but... that's the point of programming right? (To be lazy.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
汤姆,这没有简单的方法,您需要存储所有数据,甚至可能存储到文件/数据库中,几天后甚至重新启动后返回游戏将是一个很棒的功能。
您必须存储数据的原因是 Android 处理内存,因此它可以决定终止您的应用程序以尝试释放内存。
There is no easy way tom , you will need to store all your data , possibly even to a file/database and it will be a great feature to return to a game after a few days , even after a restart.
The reason you have to store data is Android handles the memory,due to which it can decide to kill your app in an attempt to free memory.
查看
Activity.onPause()
和Activity.onResume()
。如果您需要保存持久状态,请查看文档那。Check out
Activity.onPause()
andActivity.onResume()
. If you need to save persistent state, check out the docs on that.