什么是Android中最简单的方式,让每一个应用程序运行后的物品价值? [英] What is the simplest way in Android to keep an objects value after every app run?

查看:114
本文介绍了什么是Android中最简单的方式,让每一个应用程序运行后的物品价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是存储单个对象的值,使该对象被执行应用程序的下一次不为null,最简单的方法是什么?

What is the simplest way to store a single object value so that the object is not null the next time the app is executed?

例如:

public class MainActivity extends Activity {
    ...
    String X = "Hello"
}

我第二次运行这个程序,X仍然会被定义为你好。

The next time I run this app, X will still be defined as "Hello".

推荐答案

您需要看的存储选项的,看哪个最适合你的需求。你可能希望将其添加到共享preFS的地方,它采用了键/值对的,如果是精简版的数据。否则,你可能需要一个SQLite数据库。但 X 总是将是你好,你有它的方式,所以你需要一个函数的地方设置共享preFS或任何你使用。我假设你只要把那个code为简单起见,只是指出了这一点。

You need to look at Storage Options and see which is best for your needs. You probably want to add it to sharedprefs somewhere, which uses a key/value pair, if it is lite data. Otherwise, you may want a SQLite DB. But X is always going to be "Hello" the way you have it so you will need a function somewhere to set the sharedprefs or whatever you use. I'm assuming you just put that code for simplicity but just pointing that out.

这篇关于什么是Android中最简单的方式,让每一个应用程序运行后的物品价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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