我正在尝试使用
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的官方指南.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。