看一下这些代码:
问题
当我点击“主页按钮”时,会抛出一个异常
:从这行代码中泄漏了Activity
的窗口...
localWindowManager.addView(colourView, layoutParams);
问题:
你知道是什么原因导致的吗?
当我使用返回按钮关闭应用程序时,问题不会发生。
异常/错误日志:
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
编辑:
我该如何在Cordova Activity的onPause()、onStop()等函数中添加内容?
编辑2:
为什么这成为了一个问题呢?因为我所创建的只有一个扩展CordovaPlugin和一些辅助类的类。那就是全部了。我无法(我想)修改Activity类的主体。我能做的只有通过调用cordova.getActivity()
函数来获取对它的引用。