[英]how do I clear the device memory cache
In my android app, I am using transition scenes. 在我的Android应用中,我正在使用过渡场景。 On the Emulator, it works fine but on a physical device the more times a transition happens, the time between the transition grows, slowing down the app. 在仿真器上,它可以正常工作,但在物理设备上,转换发生的次数越多,转换之间的时间就会增加,从而降低应用程序的速度。 I need to clear the device cache memory to stop this from happening. 我需要清除设备缓存以阻止这种情况的发生。
I tried a code to clear the cache memory, but the android studio gives out a warning that the delete code will be ignored. 我尝试了清除高速缓存的代码,但是android studio发出警告,删除代码将被忽略。 I have not found any other way to do this. 我还没有找到其他方法可以做到这一点。
public void clearCache() {
Log.i(TAG, "Clearing Cache.");
File[] dir = mContext.getCacheDir().listFiles();
if(dir != null){
for (File f : dir){
f.delete();
}
}
}
The delete() method call is ignored by the system so the code doesn't work. 系统将忽略delete()方法调用,因此代码不起作用。 I need to clear the device cache can someone help. 我需要清除设备缓存可以有人帮助。
android studio gives out a warning that the delete code will be ignored
that's wrong, it does not give such warning. android studio gives out a warning that the delete code will be ignored
,但未给出此类警告。
It says that the result of f.delete()
is ignored. 它说f.delete()
的结果被忽略。
f.delete()
returns true
/ false
as the result, which means f.delete()
返回true
/ false
作为结果
true
if file has been deleted 如果文件已删除,则为true
false
if file deletion failed. 如果文件删除失败,则返回false
。 You may ignore this warning, if you don't care about the delete()
result, or check it like 如果您不关心delete()
结果,则可以忽略此警告,或者像这样检查它
for (File f : dir){
if(!f.delete()) {
//deletion failed. Do something about it
}
}
If you just want the warning to disappear, you can do something like 如果您只是想使警告消失,可以执行以下操作
for (File f : dir){
boolean ignored = f.delete();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.