我正在尝试使用 Android 应用程序类 (MyApplication.java) 将数据存储在一些字符串和整数的 ArrayList 中。
我希望这些数据像数据库一样永久存储,但不使用数据库,以简化我的应用程序。
当前数据已存储,当我退出应用程序时,应用程序的进程仍在后台运行。但是,如果我终止应用程序的进程,存储在 MyApplication.java 类中的数据将被删除。因此,我需要某种函数将 MyApplication 变量中的数据存储在一个文件中,以及另一个将数据恢复到变量中的函数。
有没有简单易行的方法解决这个问题?
代码恢复:
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 卡)。
官方指南is available here .
关于android - 如何在不使用数据库的情况下轻松存储持久化数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6826735/