我已经定义了一个在多进程模式下使用的 SharedPreferences
实例。
public class Prefs {
private static SharedPreferences prefs;
private static SharedPreferences.Editor editor;
private static void init(Context context) {
prefs = context.getSharedPreferences("alaki",
Context.MODE_MULTI_PROCESS);
editor = prefs.edit();
}
// static methods to set and get preferences
}
现在我正在使用这个类来处理一个独立进程的服务,同时也在我的主应用程序进程中以静态方式使用。
一切都很顺利,但有时候SharedPreferences实例上存储的所有数据都会被删除!
我该如何解决这个问题?
编辑: 最终我通过IPC解决了我的问题。