活动已经泄露的窗口 - 机器人 [英] Activity has leaked window - Android

查看:179
本文介绍了活动已经泄露的窗口 - 机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看这些作品code:

Look at these pieces of code:

<一个href="http://stackoverflow.com/questions/21728673/custom-views-and-window-attributes-on-android/21817006?noredirect=1#comment33018439_21817006">Custom意见及窗口在Android 属性

问题

当我点击Home键,除了被抛出:活动已泄漏的窗口...从这个行:

When I click 'Home button', exception is thrown: Activity has leaked window... from this line:

localWindowManager.addView(colourView, layoutParams);

问题(S)

你知道什么会导致呢?

不会出现问题,当我关闭应用程序的后退按钮。

Problem doesn't occur, when I close application with back button.

异常/错误日志

W/InputManagerService(   96): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@40908148 (uid=10056 pid=1368)
D/CordovaActivity( 1368): CordovaActivity.onDestroy()
D/CordovaWebView( 1368): >>> loadUrlNow()
E/WindowManager( 1368): Activity com.phonegap.helloworld.HelloWorld has leaked window pl.edu.uj.tcs.student.xxx.Display$Layer@40589368 that was originally added here
E/WindowManager( 1368): android.view.WindowLeaked: Activity com.phonegap.helloworld.HelloWorld has leaked window pl.edu.uj.tcs.student.xxx.Display$Layer@40589368 that was originally added here
E/WindowManager( 1368):         at android.view.ViewRoot.<init>(ViewRoot.java:258)
E/WindowManager( 1368):         at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
E/WindowManager( 1368):         at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
E/WindowManager( 1368):         at android.view.Window$LocalWindowManager.addView(Window.java:424)
E/WindowManager( 1368):         at pl.edu.uj.tcs.student.xxx.Display.setColorsViews(Display.java:181)
E/WindowManager( 1368):         at pl.edu.uj.tcs.student.xxx.Display$3.run(Display.java:139)
E/WindowManager( 1368):         at android.os.Handler.handleCallback(Handler.java:587)
E/WindowManager( 1368):         at android.os.Handler.dispatchMessage(Handler.java:92)
E/WindowManager( 1368):         at android.os.Looper.loop(Looper.java:130)
E/WindowManager( 1368):         at android.app.ActivityThread.main(ActivityThread.java:3683)
E/WindowManager( 1368):         at java.lang.reflect.Method.invokeNative(NativeMethod)
E/WindowManager( 1368):         at java.lang.reflect.Method.invoke(Method.java:507)
E/WindowManager( 1368):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/WindowManager( 1368):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/WindowManager( 1368):         at dalvik.system.NativeStart.main(Native Method)

D/CordovaActivity( 1368): onMessage(onPageStarted,about:blank)
D/CordovaWebViewClient( 1368): onPageFinished(about:blank)
D/CordovaActivity( 1368): onMessage(onPageFinished,about:blank)
D/CordovaActivity( 1368): onMessage(exit,null)
I/power   (   96): *** set_screen_state 0

编辑:

我怎么可以添加东西的onPause()的onStop()等中的科尔多瓦活动的功能呢?

How can I add something to onPause(), onStop() etc. functions in Cordova Activity?

编辑2:

这是为什么有问题?因为我所创建是一个扩展CordovaPlugin和小型辅助的类的类。就这样。我不能(我想)修改活动类主体。我所能做的就是引用它通过调用 cordova.getActivity()的功能。

Why is that a problem? Because all I create is class that extends CordovaPlugin and small auxilary classes. That's all. I'm not able (I suppose) to modify Activity class body. All I can do is get reference to it by calling cordova.getActivity() function.

推荐答案

总之一切继承人实际发生的事情。

To sum up everything heres what is actually happening.

什么是编程泄漏?

这是您获取和不释放导致内存leak.Similar将发生在(窗口/对话框)​​的内存。

The memory that you acquire and do not release lead to the memory leak.Similar happens with the (windows/dialogs).

这里发生了什么?

您试图添加一个窗口,虽然它显示了它的前景,但是当你pressing家里就被停了下来,然后被通过的onStop()停止。 所以,你的CustomView保持连接到现在有disappeared.Hence根据系统的customView占领它没有释放空间的窗口。

You are trying to add a window and while it shows up it is on the foreground,but when you are pressing the home it gets paused and then gets stopped via the onStop(). So your CustomView remains attached to the window that now has disappeared.Hence according to the system your customView occupied the space which it did not release.

解决方案

在你的的onStop()或在onPause()的onDestroy()确保您关闭您的视图(辞退()如果它是一个对话框),或者将其删除(删除()如果使用的窗口管理器)补充说。

Inside your onStop() or onPause()andonDestroy() make sure you dismiss your view(dismiss() if it's a dialog) or remove it(remove()if added using window Manager).

建议(忽略如果不是在上下文中)

我可以看到你正在试图让这过来下it.Adding这类的活动弹出窗口的任何事情都是有风险的,因为它可能引起泄漏问题系统警告窗口。 您可以通过服务实际添加此类窗口,现在你的警告窗口会超越你的活动,并显示无处不在设备上。

As i can observe you are trying to make a System alert window that comes over anything beneath it.Adding such kind of pop ups in the activity is risky as it may cause leakage problems. You may actually add such kind of window via a Service and now your alert window outlives your activity and shows up everywhere on the device.

检查了这一点

添加辞退或在你的卸载功能,你提到的pressing后退按钮,你得到这个error.On退出一个应用程序,它的 onUnload()方法被调用。

Add the dismiss or remove functions inside your on unload function as you mentioned that on pressing back button you get this error.On exiting an app its onUnload() method gets called.

更新2-科尔多瓦周期

你为什么不尝试覆盖onUnload方法,在你的CordovaPlugin class.I试图寻找,但的 都在提的onPause和onResume methods.If的存在,你有onUnload在CordovaPlugin类,然后删除该视图您正在在您的视图类runOnUiThread方法。文档

Why don't you try to override onUnload method in your CordovaPlugin class.I tried finding but the docs are mentioning the existence of onPause and onResume methods.If you got onUnload in the CordovaPlugin class then remove the view you are making in your view class runOnUiThread method.

这篇关于活动已经泄露的窗口 - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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