如何在不使用数据库的情况下轻松存储持久性数据? [英] How to store persistent data easily without using databases?

查看:163
本文介绍了如何在不使用数据库的情况下轻松存储持久性数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Android应用程序类(MyApplication.java)将数据存储在某些字符串和整数的ArrayList中.

I'm trying to use Android Application class (MyApplication.java) for storing data in some ArrayLists of strings and ints.

我希望这些数据像数据库一样被永久存储,但不使用数据库,以简化我的应用程序.

I want that these data get's stored forever, like a database, but without using databases, to simplify my app.

当前存储了数据,当我退出应用程序时,应用程序的进程仍在后台运行.但是,如果我取消了应用程序的进程,则将删除存储在MyApplication.java类上的数据.因此,我需要一种将MyApplication变量中的数据存储到文件中的函数,以及将数据还原到变量中的另一种函数.

Currently the data get's stored, when I exit from the app, the process of the app still runs in background. But if I kill the process of the app, the data stored on MyApplication.java class get's removed. So I need some kind of function that stores the data from my variables of MyApplication in a file, and another function that restores the data into the variables.

有没有简单容易的方法来解决这个问题?

Is there a simple and easy way to solve this?

代码已恢复:

public class MyApplication extends Application {
    public static String LeagueTable[][] = new String[21][8];
    //COLUMNAS MATRIZ:
    //0     /1   /2   /3   /4   /5   /6   /7
    //nombre/P.J./P.G./P.E./P.P./G.F./G.C./Pts

    public static League LFP = new League();
    public static Category Primera = new Category(20);
    public static int NEQUIPOS=20;
    public static int[][] matriz= new int[NEQUIPOS+1][NEQUIPOS+1]; //esta es la matriz de emparejamientos, representa el calendario
    public static int PlayerTeamID;
    public static boolean ExistingSaveGame=false;//esto es true cuando existe una partida guardada

    //variables candidatas a poner dentro de una de las clases del modelo, como season por ejemplo
    public static int RoundNumber; //jornada actual
    public static boolean SeasonOver=false;//true cuando la temporada ha terminado

    public void onCreate() {
        super.onCreate();
    }

    public void onTerminate() {
        super.onTerminate();
    }

"and a lot of functions that works with the static variables"

推荐答案

取决于您的上下文(尤其是但不仅与数据大小有关),您可能希望使用共享首选项,内部存储或外部存储(SD卡).

Depending of your context (especially but not only related to the size of your data), you may want to use the Shared Preferences, the internal storage or the external storage (the SD card).

有关此处的官方指南

这篇关于如何在不使用数据库的情况下轻松存储持久性数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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