I am displaying a fairly large image in a webview so that the pinch-to-zoom functions and other conveniences for viewing are already available.
It displays correctly the first time. But after leaving the activity and coming back to it, the app crashes on an OutofMemoryError related to the webview thread.
I have attempted several things to try to close the webview or stop the thread, or clear its use of memory, but to no avail. Here are examples of code that I added to my activities' onStop()
function
wv.stopLoading();
wv.clearCache(true);
//removeView(wv);
wv.clearView();
wv.freeMemory();
wv.destroy();
try {
Class.forName("android.webkit.WebView").getMethod("onPause", (Class[]) null).invoke(wv, (Object[]) null);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Anyway feel free to criticize any of those lines of code, but the point is that they have no influence on the error at all! It has to do with the webviewcore thread itself not releasing memory.
This is alarming to me because even if I was using a smaller image, this looks like it would still eventually happen. Help?