android – 如何在不使用数据库的情况下轻松存储持久数据?

前端之家收集整理的这篇文章主要介绍了android – 如何在不使用数据库的情况下轻松存储持久数据?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用 Android Application类(MyApplication.java)将数据存储在一些字符串和整数的ArrayLists中.

我希望这些数据永远存储,如数据库,但不使用数据库,以简化我的应用程序.

目前存储了数据,当我从应用程序退出时,应用程序的进程仍然在后台运行.但是,如果我杀死了应用程序的进程,那么MyApplication.java类中存储的数据就会被删除.所以我需要某种函数将MyApplication变量中的数据存储在一个文件中,另一个函数将数据恢复到变量中.

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

代码恢复:

  1. public class MyApplication extends Application {
  2. public static String LeagueTable[][] = new String[21][8];
  3. //COLUMNAS MATRIZ:
  4. //0 /1 /2 /3 /4 /5 /6 /7
  5. //nombre/P.J./P.G./P.E./P.P./G.F./G.C./Pts
  6.  
  7. public static League LFP = new League();
  8. public static Category Primera = new Category(20);
  9. public static int NEQUIPOS=20;
  10. public static int[][] matriz= new int[NEQUIPOS+1][NEQUIPOS+1]; //esta es la matriz de emparejamientos,representa el calendario
  11. public static int PlayerTeamID;
  12. public static boolean ExistingSaveGame=false;//esto es true cuando existe una partida guardada
  13.  
  14. //variables candidatas a poner dentro de una de las clases del modelo,como season por ejemplo
  15. public static int RoundNumber; //jornada actual
  16. public static boolean SeasonOver=false;//true cuando la temporada ha terminado
  17.  
  18. public void onCreate() {
  19. super.onCreate();
  20. }
  21.  
  22. public void onTerminate() {
  23. super.onTerminate();
  24. }
  25.  
  26. "and a lot of functions that works with the static variables"

解决方法

根据您的上下文(特别是但不仅与数据大小相关),您可能需要使用共享首选项,内部存储或外部存储(SD卡).

关于is available here的官方指南.

猜你在找的Android相关文章