跟踪查看加入到窗口管理器(无findViewById()函数?) [英] Keeping track of View added to WindowManager (no findViewById() function?)

查看:94
本文介绍了跟踪查看加入到窗口管理器(无findViewById()函数?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的服务我添加一个以窗口管理器 addView()。当我准备好隐瞒的观点,我称之为 removeView()使用查看引用。这个伟大的工程 - 大多数时间

我有说这个观点是没有连接到窗口管理器偶尔强制关闭的报告。这是有道理的。问题是,我觉得服务是获取杀害的Andr​​oid,而当它的时间来隐藏视图,它试图removeView上错了查看

我已经试过检查视图为空,但显然它不是在这一点上,它根本没有连接到窗口管理器之一。看来,如果在视图基准丢失,也没有办法来访问它再次

我怎样才能获得 findViewById()对相当于窗口管理器本身?在查看自动窗口管理器删除,如果我的服务被停止(杀死)?有没有一种方法,我可以存储引用查看这样,如果该服务被停止我仍然可以删除查看以后(我也试图避免泄漏查看)?

解决方案
  

在我的服务我添加一个视图窗口管理与addView()。当我准备好隐瞒的观点,我称之为removeView()使用视图的参考。这个伟大的工程 - 大部分时间。我有说的观点是没有连接到窗口管理偶尔强制关闭的报告。

我有完全相同的问题。希望专家会附和

  

我怎样才能得到findViewById()的窗口管理器本身?

相当于

请引用添加的查看和简单地使用removeView(MVIEW)。

目前在我的服务,以添加观点:

  WindowManager.LayoutParams PARAMS = ...
MVIEW =新景(本);
窗口管理WM =(窗口管理器)getSystemService(WINDOW_SERVICE);
wm.addView(MVIEW,则params);
 

然后通过捕捉异常删除的看法,我尽量避免偶尔FC:

 窗口管理WM =(窗口管理器)getSystemService(WINDOW_SERVICE);
尝试 {
    wm.removeView(MVIEW);
}赶上(例外五){}
 

  

认为自动从窗口管理器中删除,如果我的服务被停止(杀死)?

在我的经验中,它们被删除时,该服务被杀害。您可以通过不删除的意见停止服务进行测试。不知道为什么,虽然工作。

我担心的是我的第二个参照西医是不同的,当我去删除视图。如果是这样的话,是MVIEW仍在当我捕捉到了异常显示?我会尝试保持一个参考WM时,我想补充的观点,但我有问题,其中提到系统服务似乎走坏随着时间的推移。

让我知道,如果你解决过这个问题。

In my service I add a view to WindowManager with addView(). When I'm ready to hide the view, I call removeView() using the View reference. This works great -- most of the time.

I have occasional Force Close reports that say that the View is not attached to the WindowManager. This makes sense. The problem is that I think the service is getting killed by Android, and when it is time to hide the view, it attempts to removeView on the wrong View.

I have tried checking for the View to be null, but apparently it isn't at this point, it simply isn't the one attached to the WindowManager. It seems that if the View reference is lost, there is no way to gain access to it again.

How can I get the equivalent of findViewById() on the WindowManager itself? Is the View automatically removed from WindowManager if my service is stopped (killed)? Is there a way I can store the reference to the View so that if the service is stopped I can still remove the View later (I'm also trying to avoid leaking the View)?

解决方案

In my service I add a view to WindowManager with addView(). When I'm ready to hide the view, I call removeView() using the View reference. This works great--most of the time. I have occasional Force Close reports that say that the View is not attached to the WindowManager.

I am having the exact same problem. Hopefully an expert will chime in.

How can I get the equivalent of findViewById() on the WindowManager itself?

Keep a reference to the View that was added and simply use removeView(mView).

Currently in my Service, to add the view:

WindowManager.LayoutParams params = ...
mView = new View(this);
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mView, params);

Then to remove the view, I avoid occasional FC by catching the exception:

WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
try {
    wm.removeView(mView);
} catch (Exception e) {}

Is the View automatically removed from WindowManager if my service is stopped (killed)?

In my experience, they are removed when the service is killed. You can test this by stopping your service without removing the views. No idea why that works though.

My concern is that my second reference to the WM is different when I go to remove the view. If that is the case, is mView still being displayed when I catch the exception? I would try keeping a reference to the WM when I add the view, but I've had issues where references to System Services seem to go bad over time.

Let me know if you ever solved this problem.

这篇关于跟踪查看加入到窗口管理器(无findViewById()函数?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆