如何在Android上保存临时数据? [英] How do I save temporary data on android?

查看:484
本文介绍了如何在Android上保存临时数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何保存一些临时数据,以便在关闭应用程序时所有数据都消失了?我尝试了sharedPreferences,但是当我再次打开应用程序时,数据似乎仍然存在。

How can I save some temporary data so that when I close the application all the data is gone? I've tried sharedPreferences but it seems that the data is still there when I open up the application once again.

我听说您可以将数据保存到某些缓存中内存,但我真的不希望在应用程序仍在启动和运行时如果内存已满,数据就不会丢失。也许我应该使用一些全局变量?

I've heard that you can save data to some cache memory, but I really don't want the data to be gone if the memory gets "filled" when the app is still up and running. Maybe I should go with some global variables? Not that I know how I could get that to work.

我的简单应用程序是一个游戏,当您更进一步时,它会打开并关闭活动。这基本上是一个充满愚蠢图片^^的游戏。在一个活动中完成的工作应该保存在某个地方,因此,如果我回去,我可以加载数据并使它看起来像活动结束前一样。我希望你能理解我的意思。

My simple app, which is a "game", opens up and closes activities when you go one step further. It's basically a game filled with stupid pictures ^^. Stuff that has been done in one activity should be saved somewhere, So if i go back I can load the data and make it look like it was before the activity was closed. I hope you understand what I'm saying..

任何想法我如何存储一些在您需要时也易于访问的信息。

Any ideas how I could store some information that is also easy accessible when you need it.

推荐答案

使用全局变量。

onCreate 定义变量,例如:

int i;

String s = myString

然后,您可以在任何函数中访问/更改它们。

Then you can access/change them in any function.

希望我帮助了:)

这篇关于如何在Android上保存临时数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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