Hi,
Sometimes we face different kind of problems with cache of an application in android like showing old data for a web page in a Web view and the same problems will arise for a URLConnection also.
If you are working with a GPS based application, There it will generate big size of cache files. It is better to delete this cache. Here is the sample Activity for doing this job. It will identify the directory containing these cache files and delete them.
Thanks,
Álvaro
Sometimes we face different kind of problems with cache of an application in android like showing old data for a web page in a Web view and the same problems will arise for a URLConnection also.
If you are working with a GPS based application, There it will generate big size of cache files. It is better to delete this cache. Here is the sample Activity for doing this job. It will identify the directory containing these cache files and delete them.
- Code:
import java.io.File;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
public class HelloWorld extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle *) {
super.onCreate(*);
setContentView(R.layout.main);
}
@Override
protected void onStop(){
super.onStop();
}
//Fires after the OnStop() state
@Override
protected void onDestroy() {
super.onDestroy();
try {
trimCache(this);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void trimCache(Context context) {
try {
File dir = context.getCacheDir();
if (dir != null && dir.isDirectory()) {
deleteDir(dir);
}
} catch (Exception e) {
// TODO: handle exception
}
}
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;
}
}
}
// The directory is now empty so delete it
return dir.delete();
}
}
Thanks,
Álvaro


» Memory, final code and final video (in Spanish)
» ODROID-A4 IO Board
» odroid linux kernel config file "hkdk_rtm20_defconfig " missed
» odroid-7 source code
» Application source code for Embedded Android Platform based on ODROID-A4
» What is ODROID-BaB project LSED?
» CPU Module S5PV310 and K3PE7E700B
» BF040-I50B_N09 Board to Board Connector
» CPU Module Schematics
» A stupid question : How can I root the ODROID-A
» ODROID-PC Ubuntu 12.04 with HDMI
» ODROID-A4 IO Board - Oscilloscope
» OPEN RFID Tag
» About the recovery tool for Odroid-pc