我需要找到一种方法如何清除我的应用程序存储在缓存中的数据.基本上我使用Fedor(在ListView中的图像的延迟加载)惰性列表实现,我想在我加载例如100个图像时自动清除缓存.任何想法怎么做?
编辑: 代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list=(ListView)findViewById(R.id.list);
adapter=new LazyAdapter(this, mStrings);
list.setAdapter(adapter);
deleteCache(this);
adapter.notifyDataSetChanged();
}
public static void deleteCache(Context context) {
try {
File dir = context.getCacheDir();
if (dir != null && dir.isDirectory()) {
deleteDir(dir);
}
} catch (Exception e) {}
}
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 …Run Code Online (Sandbox Code Playgroud) 为了为用户提供清除缓存的快速方法,我使用附加到“清除缓存”按钮的以下函数(基于this和this):
static void clearAppCache(Context context) {
try {
File dir = context.getCacheDir();
deleteDir(dir);
} catch (Exception e) {
// TODO: handle exception
}
}
private static boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (String aChildren : children) {
boolean success = deleteDir(new File(dir, aChildren));
if (!success) {
return false;
}
}
return dir.delete();
} else if (dir!= null && dir.isFile()) {
return dir.delete();
} else {
return …Run Code Online (Sandbox Code Playgroud) 我想以编程方式删除我的应用程序中的缓存文件.
我如何在代码中执行此操作?
我想启动一项服务(我已经设置了这项服务).
仅供参考 - IDK为什么我的录取率很低.我已经接受了我的大部分或全部答案.