I've made a class to pickle and unpickle data from a dictionary. Its fairly standard: it tried to open the file, if the file's not present it creates it and it offers methods to read from the dictionary and write to the dictionary.
However, when packaged as an APK using buildozer (I made sure to delete the data file before compiling), sometimes data is randomly lost on the device, and if you update the app through the android updater all data is lost. I don't know where the data file is, but I'm presuming it's kept in the APK. Can anyone offer a solution to this?
I'm using Python 2 and Kivy 1.10 and the built-in pickle module. Thanks in advance
The code for my pickler is as below:
import pickle
class Data(object):
def __init__(self,fname):
try:
f = open(fname,'r')
p = pickle.load(f)
f.close()
except IOError:
f = open(fname,'w')
pickle.dump({'highscore':0},f)
f.close() p = {'highscore':0}
self.fname = fname
self.data = p
def rewrite(self,key,value):
new = self.data
new[key] = value
f = open(self.fname,'w')
pickle.dump(new,f)
f.close()
self.data = new
def grab(self,key):
with open(self.fname,'r') as f:
self.data = pickle.load(f)
return self.data[key]