admin管理员组文章数量:1399915
I want to clear my Android app's cache programmatically, similar to how we do it from Settings > Apps > App Info > Storage & Cache > Clear Cache, but without deleting any app data. I've tried using the following function:
fun cleanCache(context: Context) {
try {
context.cacheDir.deleteRecursively()
context.externalCacheDir?.deleteRecursively()
context.toast("Cache cleared successfully")
} catch (ignore: Exception) {
context.toast("Failed to clear Cache")
}
}
Additionally, I have cleared: WebView cache, Image loader memory cache, External caches.
Even after running this function, the cache is cleared but not entirely like when clearing it manually from system settings. How can I clear only the app cache (without affecting app data) exactly like the system "Clear Cache" button in App Info?
Questions: Is there a proper way to programmatically clear all app cache, similar to the system’s "Clear Cache" button? Are there any system permissions or APIs required to ensure complete cache clearing?
Any guidance or alternative approaches would be appreciated!
本文标签: kotlinHow to Clear App Cache in Android (Like in App Info) Without Deleting DataStack Overflow
版权声明:本文标题:kotlin - How to Clear App Cache in Android (Like in App Info) Without Deleting Data? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744206884a2595231.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论