本文介绍了以编程方式清除Android我的应用程序中的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想在设置退出时清除应用程序缓存内存。
我想要参考/帮助/处理我的应用程序的代码。
提前谢谢。
Hi Everyone,
I want to clear my application cache memory when it set to exit.
I want reference/help/code that handles my application.
Thanks in advance.
推荐答案
Java.Lang.Runtime.GetRuntime().RunFinalization();
Java.Lang.Runtime.GetRuntime().Gc();
trimCache(this.ApplicationContext);
public void trimCache(Context context)
{
try
{
Java.IO.File dir = context.CacheDir;
if (dir != null && dir.IsDirectory)
{
deleteDir(dir);
}
context.DeleteDatabase("webview.db");
context.DeleteDatabase("webviewCache.db");
}
catch (Exception e)
{
CostantsLift.WriteTextFile(" trimCache ", e.Message, currDate);
// TODO: handle exception
}
}
public bool deleteDir(Java.IO.File dir)
{
if (dir != null && dir.IsDirectory)
{
String[] children = dir.List();
foreach (string child in children)
//for (int i = 0; i < children.Length; i++)
{
bool success = deleteDir(new Java.IO.File(dir, child));
if (!success)
{
return false;
}
}
}
// The directory is now empty so delete it
return dir.Delete();
}
这篇关于以编程方式清除Android我的应用程序中的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!