9

I am playing a video in a WebView.

If a memory leak is to be avoided, the ApplicationContext (as against an Activity context) has to be used to instantiate the WebView (refer to this)

If I pass in the ApplicationContext and the VideoView inside the WebView needs to create a dialog (typically for 'Cannot play this Video'), I get a BadTokenException (refer to this)

Are we expected to decide between a memory leak or a potential ANR?

Community
  • 1
  • 1
Vikram Bodicherla
  • 7,133
  • 4
  • 28
  • 34

2 Answers2

0

I conclude from above comments and further tests, that the problem is a bug in the SDK: when creating a WebView via XML layout, the activity is passed as the context for the WebView, not the application context. When finishing the activity, the WebView still keeps references to the activity, therefore the activity doesn't get removed from the memory. I filed a bug report for that , see the link in the comment above.

webView = new WebView(getApplicationContext());
GOLDEE
  • 2,318
  • 3
  • 25
  • 49
0

This is definitely a bug, or the api design is really bad, it does not give any hint of the error. I believe many developers met this problem.

Charlesjean
  • 566
  • 1
  • 5
  • 16