hi ! i am very new to android. i want to develop an application for study in which clicking on one button will clear the cache memory of all application installed in android device.i know this type of app is available on Google play but i want to develop it myself. i try the following code but it clear the cache memory of current one application and throw Null Pointer Exception. i have a need of clearing cache memory of each and every application simultaneously. please help me to solve this problem.Thanks in advance..


Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);


List<ResolveInfo> mainList = getPackageManager().queryIntentActivities(mainInte nt, 0);

Context context;

for(ResolveInfo rInfo : mainList)

String packageName = rInfo.activityInfo.applicationInfo.packageName;

context = createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY);



public void clearApplicationData(Context context) {


File cache = context.getCacheDir();

File appDir = new File(cache.getParent());
String[] children = appDir.list();
for(String s : children){
deleteDir(new File(appDir, s));
Log.i("TAG", "File /data/data/APP_PACKAGE/" + s +" DELETED");