Websettings.SetAppCacheEnabled deprecated, what to use instead?
Asked Answered
M

2

38

During an attempt to bring an older android application into the modern world, I have come across the deprecated statement of:

websettings.setAppCacheEnabled(false)

What is the modern Androidx alternate?

Marienthal answered 25/8, 2022 at 13:10 Comment(1)
did u get solution ?Cenac
C
36

Use this

webView.settings.cacheMode=WebSettings.LOAD_NO_CACHE

Refer : https://developer.android.com/reference/android/webkit/WebSettings

Cenac answered 21/10, 2022 at 11:40 Comment(2)
what if I had websettings.setAppCacheEnabled(true), what should I set now?Caption
@Caption You can always opt-in for cache data using WebSettings.LOAD_CACHE_ONLY or .LOAD_CACHE_ELSE_NETWORK.Sashenka
B
30

Alternatively, this helped me out:

webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
Babita answered 14/12, 2022 at 17:20 Comment(3)
what if I had websettings.setAppCacheEnabled(true), what should I set now?Caption
@Caption this line of code is not depreciated, that's why we have the new line of code that gives the same result.Babita
@Caption use webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); or webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); LOAD_DEFAULT does not use expired cache but LOAD_CACHE_ELSE_NETWORK doesClaman

© 2022 - 2024 — McMap. All rights reserved.