在我的应用程序中,我有一个在下面的代码中与FileOutputStream一起存储的对象的列表。此外,我的应用程序中存储有SharedPreferences中的任何设置。无论何时我第一次在Google Play商店更新我的应用程序(对于那些不熟悉此流程的用户,我上传了新的APK),所有使用该应用程序的对象都被删除,并且所有设置均被设置为默认值。为什么要这样做?如何将对象存储在更新后不会消失的地方?为什么Android更新我的应用程序擦除信息?
public ObjectStorage readListFromFile()
{
ObjectStorage temp = null;
String filename = "storefileobj";
FileInputStream fis;
try {
fis = getActivity().openFileInput(filename);
ObjectInputStream is = new ObjectInputStream(fis);
temp = (ObjectStorage) is.readObject();
is.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (StreamCorruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return temp;
}
public void updateStorage()
{
String filename = "storefileobj";
FileOutputStream fos;
try {
fos = getActivity().openFileOutput(filename, Context.MODE_PRIVATE);
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(mainObjectList);
os.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
有一件事是我知道的事实,用户不需要重新安装。所以我猜这意味着数据格式必须改变?因为在存储数据时我没有触及代码。 – AggieDev