How to Clear App chache


#1

Hi, I am still having issues with clearing App cache. please can someone help me out some sample tested codes.


#2

It is unclear what you are referring to when you are saying ‘App cache’. Could you please elaborate? It would also help by showing what you’ve done so far, and what difficulties you’ve faced.


#3

I want do something like this public void clearApplicationData()
{
File cache = getCacheDir();
File appDir = new File(cache.getParent());
if (appDir.exists()) {
String[] children = appDir.list();
for (String s : children) {
if (!s.equals(“lib”)) {
deleteDir(new File(appDir, s));Log.i(“TAG”, “**************** File /data/data/APP_PACKAGE/” + s + " DELETED *******************");
}
}
}
}

public static boolean deleteDir(File dir)
{
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
return dir.delete();
}


#4

Please read a bit on
https://docs.nativescript.org/core-concepts/accessing-native-apis-with-javascript
and
https://docs.nativescript.org/runtimes/android/marshalling/js-to-java
to learn how to write JavaScript that will call to Java.

Offtopic:
Also, I am not sure you should delete the directories that are supposedly removed from the code you shared. The javascript, images, xml assets, the metadata all live inside /data/data/APP_PACKAGE/files and are needed to ensure your NativeScript application actually works.


#5

I have read and been using it. so let me clarify @Pete.K what I want do is for example…in android settings - applications - then you clear cache for the app…that’s the cache am talking about…


#6

this is what I want to be able to clear automatically using code