http://stackoverflow.com/questions/3130654/memory-leak-in-webview



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());
share | edit answered Jun 28 '10 at 12:56 Mathias Lin
11.8k 4 42 84
1
ty for that getApplicationContext() actually worked on my memory leak when creating the WebView. But when i add the webview to another ViewGroup the memory Leak appears again. My wild guess is that adopts the parent's baseContext. Is there anyworkAround to that? I create the parent with getApplicationContext() too... so i guess i'm out of theories– weakwire Sep 20 '11 at 1:34
4
Note that using the application context means that you won't be able to click on links in your webview, since doing so will result in a crash: "Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?"– emmby Jan 20 '12 at 23:47
@emmby Thanks for the hint, wasn't thinking of that, as I just needed the webview to display more complex html (beyond what you can do with a TextView), but no links in it. Therefore, I didn't come across the issue you mentioned, but thanks for pointing it out again. +1– Mathias Lin Jun 18 '12 at 15:27
2
Also, any time the webview attempts to create a dialog (e.g., to remember a password, etc), the webview will crash as it expects an activity context.– markshiz Aug 30 '12 at 18:13
1
It crush app when webView want to display dialog for example asking "Do you want save passwaord" then it will crush :(– Gelldur Dec 30 '12 at 20:52

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(Java):Android的状态栏通知(Noti
  2. Funambol android eclipse上的配置及说明
  3. android 、java优质资料合集
  4. Android(安卓)4.0的图形硬件加速及绘制技
  5. 解决Android Studio Gradle DSL method n
  6. Android访问WebService
  7. Android开发之SlidingDrawer(一)
  8. 使用Android提供的模拟任意地理位置,报jav
  9. Android 中文 API (34) —— RadioGroup
  10. appwidget-provider