我希望一旦你清除了缓存就会被发送到MainActivity。代码就是这个,我该怎么办?
Preference cache;
cache = this.findPreference("cache");
cache.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(final Preference preference) {
clearCache(Class.this);
return true;
}
});
}
public void clearCache(final Context context) {
final File cache = context.getCacheDir();
final File appDir = new File(cache.getParent());
if (appDir.exists()) {
final String[] children = appDir.list();
for (final String childFilePath : children)
if (!childFilePath.equals("lib")) {
deleteDir(new File(appDir, childFilePath));
Log.i("TAG", "**************** File /data/data/com.X.XX/" + childFilePath
+ " DELETED *******************");
Toast.makeText(getBaseContext(), "CLEAN", Toast.LENGTH_LONG).show();
}
}
}
public boolean deleteDir(final File dir) {
if (dir == null)
return true;
if (dir.isDirectory()) {
final String[] children = dir.list();
for (final String childFilePath : children) {
final boolean success = deleteDir(new File(dir, childFilePath));
if (!success)
return false;
}
}
return dir.delete();
让我解释一下,一旦删除缓存并且数据已成功执行,您必须将其发送到MainActivity。感谢!!!
答案 0 :(得分:0)
致电finish()
,活动将关闭,您将返回上一个
答案 1 :(得分:0)
if (appDir.exists()) {
final String[] children = appDir.list();
for (final String childFilePath : children)
if (!childFilePath.equals("lib")) {
deleteDir(new File(appDir, childFilePath));
Log.i("TAG", "**************** File /data/data/com.X.XX/" + childFilePath
+ " DELETED *******************");
Toast.makeText(getBaseContext(), "CLEAN", Toast.LENGTH_LONG).show();
}
}
startActivity(new Intent(context,MainActivity.class));
}
我希望它会有所帮助!!