android - 强制安装新的解析器

标签 android parse-platform

正如我之前在这个问题中提出的: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/

相关文章:

java - 如何制作联系人 ListView ?

android - 后台服务提供数据供以后使用最佳实践

android - adb shell pm : command grant not found

android - 如何将电子邮件链接添加到布局 xml,Android

ios - 如何从 PFUser 解包 Optionals 链以访问 bool 值

arrays - 合并自定义对象数组以形成新对象

java - 我的 getter 返回错误值

ios - prepareForSegue 在 performSegue 之前调用

android - 在方法中我的列表有元素,但是当我出来时列表是空的

ios - 如何从 UITableView 单元格检索解析对象并将其呈现在详细 View Controller 中