Trying to figure out why i cannot clear cache from mutliple webviews i have, i seem to get a force close error when i have the code this way below. however when its just 1 webview it works fine. Any Suggestions guys.
Section that Doesnt Work due to Multiple Webview
Preference customPref = (Preference) findPreference("clearcache");
customPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
// When Cache Preference is clicked
public boolean onPreferenceClick(Preference preference) {
Toast.makeText(getBaseContext(), "Cache Cleared",
Toast.LENGTH_LONG).show();
WebViewClientDemoActivity.web.clearCache(true);
Commercial.web4.clearCache(true);
Community.web2.clearCache(true);
Distributors.web6.clearCache(true);
Downloads.web7.clearCache(true);
EnlightenInfoPage.web4.clearCache(true);
Support.web3.clearCache(true);
return false;
}
});
Its Works with just this
WebViewClientDemoActivity.web.clearCache(true);
All ove the webview are indead webviews and do get used, is statement stuff i dont have or soemthing like that.
Or if you know of a way to clear the applications cache not data, just cache using a on Preference Click
LOGCAT
08-29 20:46:14.413: E/AndroidRuntime(337): FATAL EXCEPTION: main
08-29 20:46:14.413: E/AndroidRuntime(337): java.lang.NullPointerException
08-29 20:46:14.413: E/AndroidRuntime(337): at com.jaisonbrooks.enlighten.Prefs$1.onPreferenceClick(Prefs.java:60)
08-29 20:46:14.413: E/AndroidRuntime(337): at android.preference.Preference.performClick(Preference.java:812)
08-29 20:46:14.413: E/AndroidRuntime(337): at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:190)
08-29 20:46:14.413: E/AndroidRuntime(337): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
08-29 20:46:14.413: E/AndroidRuntime(337): at android.widget.ListView.performItemClick(ListView.java:3382)
08-29 20:46:14.413: E/AndroidRuntime(337): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
08-29 20:46:14.413: E/AndroidRuntime(337): at android.os.Handler.handleCallback(Handler.java:587)
08-29 20:46:14.413: E/AndroidRuntime(337): at android.os.Handler.dispatchMessage(Handler.java:92)
08-29 20:46:14.413: E/AndroidRuntime(337): at android.os.Looper.loop(Looper.java:123)
08-29 20:46:14.413: E/AndroidRuntime(337): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-29 20:46:14.413: E/AndroidRuntime(337): at java.lang.reflect.Method.invokeNative(Native Method)
08-29 20:46:14.413: E/AndroidRuntime(337): at java.lang.reflect.Method.invoke(Method.java:521)
08-29 20:46:14.413: E/AndroidRuntime(337): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-29 20:46:14.413: E/AndroidRuntime(337): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-29 20:46:14.413: E/AndroidRuntime(337): at dalvik.system.NativeStart.main(Native Method)
Maybe one of the webviews is null, Its never good to access UI elements of another activity. Moreover, only if you have started all activities atleast once will the webviews initialized. Add a null check for each web element
But I think its bad design to have static elements, can these activities have only one instance? You will have to ensure that all the activities are singletons
Edit:
If you want to delete Cachedirectory of your own app you can use