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..

code:

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

mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

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

clearApplicationData(context);

}

public void clearApplicationData(Context context) {

if(context.getCacheDir()!=null)
{

File cache = context.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");
}
}
}
}