我正在尝试使用
Android Application类(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"
解决方法
根据您的上下文(特别是但不仅与数据大小相关),您可能需要使用共享首选项,内部存储或外部存储(SD卡).
关于is available here的官方指南.