正如我之前在这个问题中提出的:Clear parse installation cache on Android
我想在用户注销应用程序时删除/清除我的 Android 手机上的解析安装。我可以通过网络脚本删除解析安装,然后我必须从手机上的内存/磁盘中清除它。
我的问题是,在我这样做之后如何强制解析库触发创建新的解析安装?
最佳答案
我已经能够使用 android parse sdk 1.13.1 成功删除“本地”ParseInstallation 缓存
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
Class clazz = installation.getClass();
Method[] methods = clazz.getDeclaredMethods();
Method method1 = clazz.getDeclaredMethod("getCurrentInstallationController");
method1.setAccessible(true);
Object result = method1.invoke(installation);
Method method2 = result.getClass().getDeclaredMethod("clearFromDisk");
method2.setAccessible(true);
String result2=(String) method2.invoke(result);
Method method3 = result.getClass().getDeclaredMethod("clearFromMemory");
method3.setAccessible(true);
String result3=(String) method3.invoke(result);
每次我的应用程序启动时,我都会检查安装是否可以保存,如果不能,我就重新创建另一个安装。
这样,根据您的用例从解析服务器中删除安装是安全的,我的 ParseInstallation 仅包含对我的用户对象的引用,因此我可以查询和发送推送通知。
final ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("user", ParseUser.getCurrentUser());
installation.saveInBackground()
.continueWithTask(new Continuation<Void, Task<Void>>() {
@Override
public Task<Void> then(Task<Void> task) throws Exception {
if (task.isFaulted()) {
try {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
Class clazz = installation.getClass();
Method[] methods = clazz.getDeclaredMethods();
Method method1 = clazz.getDeclaredMethod("getCurrentInstallationController");
method1.setAccessible(true);
Object result = method1.invoke(installation);
Method method2 = result.getClass().getDeclaredMethod("clearFromDisk");
method2.setAccessible(true);
String result2=(String) method2.invoke(result);
Method method3 = result.getClass().getDeclaredMethod("clearFromMemory");
method3.setAccessible(true);
String result3=(String) method3.invoke(result);
} catch (Exception ex) {
ex.printStackTrace();
}
}
return null;
}
})
希望这有点道理......
关于android - 强制安装新的解析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32435272/