Android method of storing data without using database

This article gives an example of how Android stores data without using a database. Share with you for your reference. The specific analysis is as follows:

In some cases, we don't need to build a database, but we have to save some data and call it when the program runs next time. What should we do?

1. Reference namespace

2. Define a new class pictureglobaldef to store data. In this class, define:

3. In the data switch to be referenced_ Open:

4. Switch to save data_ Open:

5. Read and write SharedPreferences of other applications

Sometimes we need to read and write SharedPreferences of other applications. What should we do then?

The key to reading SharedPreferences of other applications is to obtain the context of other applications:

In this way, the context of other applications is obtained

After obtaining the context, you can use the getsharedpreferences method of the context to obtain the shaerdpreferences object, so as to read and write data according to the methods of 1-4.

I hope this article will be helpful to your Android program design.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>