Reputation: 503
as I previously asked in this question: Clear parse installation cache on Android
I would like to delete/clear the parse installation on my android phone when a user logs out of the app. I can delete the parse installation via a script from the web, then I have to clear it from the ram/disk on the phone.
My question is, how can I force the parse library to trigger creating a new parse installation after I do that?
Upvotes: 3
Views: 358
Reputation: 4307
I've been able to successfully delete the 'local' ParseInstallation cache using the android parse sdk 1.13.1
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);
Everytime my app starts I check if the installation can be saved, if it can't I just recreate another installation.
This way, it's safe to delete the installation from parse-server depending on your use case, My ParseInstallation only holds a reference to my User object so I can query and send Push notifications.
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;
}
})
Hope this makes a little sense...
Upvotes: 1