【发布时间】:2016-07-23 01:55:00
【问题描述】:
我正在尝试使用 Android 应用程序类 (MyApplication.java) 将数据存储在一些字符串和整数的 ArrayLists 中。
我希望像数据库一样永久存储这些数据,但不使用数据库,以简化我的应用程序。
目前数据被存储,当我退出应用程序时,应用程序的进程仍然在后台运行。但是,如果我终止应用程序的进程,则存储在 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"
【问题讨论】:
标签: android persistence