什么是Android中最简单的方式,让每一个应用程序运行后的物品价值?最简单、应用程序、物品、价值

2023-09-04 04:25:49 作者:混吃等死

什么是存储单个对象的值,使该对象被执行应用程序的下一次不为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.