我试图保存我的应用程序的游戏状态,以便重新启动应用程序后可以重新加载。我试图保存的对象非常复杂,并且包含大量数据。我一直在寻找不同的解决方案,并尝试了很多。Android - 应用程序关闭后保存和加载对象的问题
我得到的最接近的是,应用程序能够在运行时保存和加载数据。 关闭并重新启动应用程序时,它有时也会成功加载数据,但只是在非常罕见的时刻。
有没有人知道问题可能是什么?
的Object
我试图挽救如下所示(我离开了不重要的功能):
public class SCSpieldaten implements Serializable {
private static final long serialVersionUID = 1L;
//Aktuelles Spiel
/////////////////////////////////////////////////////////////////////////////////////////
public static Random rand = new Random();
public static int EinTabletBedienung = 1;
public static int KartePortLand = 0;
public static int AktuelleRunde = 0;
public static int AktiverSpieler = 0;
public static int AktivesDorf = 0;
public static int AktuellerBauplatz = 1;
public static int AktuellStaerksterMacht[] = {KEINEANGABE,KEINEANGABE,KEINEANGABE};
public static int SelektiertePositionX = 0;
public static int SelektiertePositionY = 0;
public static int AktuellesFeld = 1;
public static int AktuellesGebaeude = 1;
public static int AktuellesGebiet = 0;
public static int AktuelleAnzahlUnit[] = {0,0,0};
public static int AktuellerEinheitentyp[] = {KEINEANGABE,KEINEANGABE,KEINEANGABE};
public static int AktuellerBericht = 0;
public static ArrayList<Integer> SpinnerBerichtNr = new ArrayList<Integer>();
public static ArrayList<ArrayAdapter<String>> ArrayAdapter = new ArrayList<ArrayAdapter<String>>();
public static ArrayList<CBericht> CB_AktuellerBericht = new ArrayList<CBericht>();
public static CKosten AktuelleKosten = new CKosten(0,0,0,0,0);
public static CGebaeude TempGebaeude = new CGebaeude();
public static ArrayList<CSpieler> CS_Spieler = new ArrayList<CSpieler>();
public static ArrayList<CNeutralesLager> CN_NeutralesLager = new ArrayList<CNeutralesLager>();
public static ArrayList<CWegzoll> CW_Wegzoll = new ArrayList<CWegzoll>();
public static CDorf CD_Handelsstadt = new CDorf(GEBIETNEUTRAL);
public static CDorf CD_Festung = new CDorf(GEBIETNEUTRAL);
public static CDorf CD_Forschungszentrum = new CDorf(GEBIETNEUTRAL);
public static CUnterstuetzung CU_FestungVerteidigung = new CUnterstuetzung();
public static CUnterstuetzung CU_FestungStartArmee = new CUnterstuetzung();
public static Integer[][] SpielerStatistic = new Integer[6][100];
public void save(Context c) throws IOException
{
FileOutputStream fos = c.openFileOutput("test0.txt", Context.MODE_WORLD_WRITEABLE);
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(this);
os.close();
}
public SCSpieldaten load(Context c) throws IOException, ClassNotFoundException
{
FileInputStream fis = c.openFileInput("test0.txt");
ObjectInputStream is = new ObjectInputStream(fis);
SCSpieldaten simpleClass = (SCSpieldaten) is.readObject();
is.close();
return simpleClass;
}
我使用ObjectOutputStream也试过,但重新启动应用程序时,它好像得了文件deleatet
大量的静态变量的!!!,想想你的RAM的负载。 – Kedarnath