在按下活动时删除数据此代码有效但应用程序崩溃
public void onBackPressed() {
File dir = context.getCacheDir();
if(dir!= null && dir.isDirectory()){
File[] children = dir.listFiles();
if (children == null) {
// Either dir does not exist or is not a directory
} else {
File temp;
for (int i = 0; i < children.length; i++) {
temp = children[i];
temp.delete();
}
}}}
提前致谢。