Android 开发 Tip 3 -- that was originally added here
来源:互联网 发布:竹笛教学的软件 编辑:程序博客网 时间:2024/06/05 16:57
转载请注明出处:http://blog.csdn.net/crazy1235/article/details/70185952
窗体句柄泄漏
异常信息如下:
xxx has leaked window DecorView@ffd62e7[title] that was originally added here
这类错误一般都是在使用AlertDialog , PopupWindow, ProgressDialog 时,关闭activity时没有将它们 dismiss() !
还原一下错误现场:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test_alert_dialog); progressDialog = ProgressDialog.show(this, "title", "loading..."); MyHandler handler = new MyHandler(this); handler.sendEmptyMessageDelayed(1, 3000); }
private static class MyHandler extends Handler { private WeakReference<TestAlertDialogActivity> reference; public MyHandler(TestAlertDialogActivity activity) { this.reference = new WeakReference<TestAlertDialogActivity>(activity); } @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (msg.what == 1 && reference.get() != null && !reference.get().isFinishing()) { reference.get().finish(); } } }
在ProgressDialog还在运行过程中,调用activity finish()方法就会出现这个错误!
解决办法
在OnDestory() 生命周期函数中,关闭该关闭的 “Dialog” !
@Override protected void onDestroy() { super.onDestroy(); if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } }
stackoverflow
http://stackoverflow.com/questions/2850573/activity-has-leaked-window-that-was-originally-added
1 0
- Android 开发 Tip 3 -- that was originally added here
- Android常见错误之android.widget.LinearLayout@4375f248 that was originally added here
- 问题:Activity has leaked window android.widget.RelativeLayout@407cd588 that was originally added here
- Android 报错:has leaked window XXXXX that was originally added here
- has leaked window com.android.internal.policy.impl.PhoneWindow$ that was originally added here异常解决
- has leaked window com.android.internal.policy.impl.PhoneWindow$ that was originally added here
- has leaked window com.android.internal.policy.impl.PhoneWindow$ that was originally added here
- 问题排查:has leaked window com.android.internal.policy.impl.PhoneWindow$ that was originally added here
- 【已解决】Activity MainActivity has leaked window PhoneWindow$DecorView@ that was originally added here
- Dialog使用时has leaked window...that was originally added here错误
- Dialog显示引起的问题 Activity has leaked window DecorView@5704632[] that was originally added here
- Activity has leaked window DecorView@ab38a0a[] that was originally added here
- android.app.ServiceConnectionLeaked: that was originally bound here
- Android 警告提示:Activity has leaked window xxxxx was originally added here
- 关于dialog关闭和activity的冲突(Activity has leaked window xxx that was originally added here)
- 关于WindowManager的一个小问题was originally added here
- Android排错:has leaked window com.android.internal.policy.impl.PhoneWindow$ that was originally added
- Android排错:has leaked window com.android.internal.policy.impl.PhoneWindow$ that was originally added
- Android 自定义控件样式 常用属性
- 4818: [Sdoi2017]序列计数
- AngularJS 控制器(Controller) 用于控制 AngularJS 应用
- C++之STL
- Android编程Checkbox复选框提示操作
- Android 开发 Tip 3 -- that was originally added here
- CUDA提供的函数评估Occupancy
- TabLayout的简单运用和若干问题的解决
- 数据结构与算法---选择排序
- 个人理解的整数自动转换原则
- HDU-3791 二叉搜索树
- 通俗易懂SpringMVC整体框架理解
- 【数据库设计】第一范式,第二范式,第三范式
- MapReduce学习总结