How to Clear App chache


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


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.


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();


Please read a bit on
to learn how to write JavaScript that will call to Java.

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.


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…


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