今天在测试模块功能时,出现WindowLeaked的问题,Log如下:
I/WorkActivity(13831): in WorkActivity...
I/WorkActivity(13831): in onCreate...from=0 isConfingChanged=false
I/WorkActivity(13831): initBroadcast...
I/WorkActivity(13831): bundle is null!!
I/WorkActivity(13831): onResume, isRmLogin=false from=0
E/aa(13831): WorkActivity ipStr=192.123.40.149
I/WorkActivity(13831): not first login, only initialize network configration!
.......
I/WorkActivity(13831): Identity init sucess
I/WorkActivity(13831): ip:192.123.40.149 port:20060 webIp=192.123.40.149 webPort=8081 UserName=houzhansheng
I/WorkActivity(13831): edVIp=android.widget.EditText{b28b2dc VFED..CL ......I. 0,0-0,0 #7f0a004f app:id/edVIp}
remoteInfo=com.ims.data.RemoteChatInfo@d9db961
I/View(13831): ssignParent(ViewParent parent) parent is: android.view.ViewRootImpl@31bea69d
I/WorkActivity(13831): showing progressDlg
I/View(13831): ssignParent(ViewParent parent) parent is: android.view.ViewRootImpl@3f5ef712
I/View(13831): ssignParent(ViewParent parent) parent is: android.widget.ListView{21c36f36 VFED.VC. ......ID 0,
0-1116,78 #7f0a0060 app:id/lstVideoRm}
I/WorkActivity(13831): onPause... isConfingChanged=true
I/WorkActivity(13831): onDestroy... isConfingChanged=false
I/View(13831): ssignParent(ViewParent parent) parent is: null
I/View(13831): ssignParent(ViewParent parent) parent is: null
E/WindowManager(13831): android.view.WindowLeaked: Activity org.doubango.imsdroid.Screens.WorkActivity
has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{a172fa4 V.E..... R.....I. 0,0-1160,324}
that was originally added here
E/WindowManager(13831): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:399)
E/WindowManager(13831): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:300)
E/WindowManager(13831): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
E/WindowManager(13831): at android.app.Dialog.show(Dialog.java:325)
E/WindowManager(13831): at org.doubango.imsdroid.Screens.WorkActivity.showLoginDlg(WorkActivity.java:1028)
E/WindowManager(13831): at org.doubango.imsdroid.Screens.WorkActivity.onResume(WorkActivity.java:630)
E/WindowManager(13831): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1265)
E/WindowManager(13831): at android.app.Activity.performResume(Activity.java:6189)
E/WindowManager(13831): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3230)
E/WindowManager(13831): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3272)
E/WindowManager(13831): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2521)
E/WindowManager(13831): at android.app.ActivityThread.access$1200(ActivityThread.java:163)
E/WindowManager(13831): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1374)
E/WindowManager(13831): at android.os.Handler.dispatchMessage(Handler.java:102)
E/WindowManager(13831): at android.os.Looper.loop(Looper.java:135)
E/WindowManager(13831): at android.app.ActivityThread.main(ActivityThread.java:5601)
E/WindowManager(13831): at java.lang.reflect.Method.invoke(Native Method)
E/WindowManager(13831): at java.lang.reflect.Method.invoke(Method.java:372)
E/WindowManager(13831): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
E/WindowManager(13831): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
I/View(13831): ssignParent(ViewParent parent) parent is: null
I/WorkActivity(13831): in WorkActivity...
I/WorkActivity(13831): in onCreate...from=0 isConfingChanged=false
I/WorkActivity(13831): initBroadcast...
I/WorkActivity(13831): onResume, isRmLogin=true from=0
E/aa(13831): WorkActivity ipStr=192.123.40.149
I/WorkActivity(13831): not first login, only initialize network configration!
分析log,Progressdlg显示异常的原因是attach时,该activity销毁重启了,所以leak。
问题是翻遍代码,也没有发现重启该activity的地方,相当诡异。
于是baidu google之后,终于有网友的慷慨提示说是不是横竖屏幕切换/软件盘/sim卡等原因引起configChanges,从而引起Activity生命周期重走导致的?
于是我在log中搜索change发现如下可疑log:
I/WorkActivity(19320): in onCreate...from=3 isConfingChanged=false
I/InputReader(3062): Reconfiguring input devices. changes=0x00000004
I/HwSystemManager(32006): HsmPackageManager:onConfigureChanged: zh_CN
I/HwSystemManager(3625): HsmPackageManager:onConfigureChanged: zh_CN
W/ws000(13240): Application#onConfigurationChanged() is invoked!!!
W/ws000(12723): Application#onConfigurationChanged() is invoked!!!
I/HwLauncher(26780): Model onReceive intent=Intent { act=android.intent.action.CONFIGURATION_CHANGED flg=0x70000010 }
I/PanelView(3267): Configuration orientation changed
I/WorkActivity(19320): onDestroy... isConfingChanged=false
I/TimeManager(3267): receiver action = android.intent.action.CONFIGURATION_CHANGED
I/TimeManager(3267): notify time change. size = 2
I/WorkActivity(19320): in onCreate...from=0 isConfingChanged=false
I/InputReader(3062): Reconfiguring input devices. changes=0x00000004
I/HwSystemManager(3625): HsmPackageManager:onConfigureChanged: zh_CN
I/HwSystemManager(32006): HsmPackageManager:onConfigureChanged: zh_CN
I/HwLauncher(26780): Model onReceive intent=Intent { act=android.intent.action.CONFIGURATION_CHANGED flg=0x70000010 }
W/ws000(13240): Application#onConfigurationChanged() is invoked!!!
W/ws000(12723): Application#onConfigurationChanged() is invoked!!!
I/WorkActivity(19320): onPause... isConfingChanged=true
I/WorkActivity(19320): onDestroy... isConfingChanged=false
I/PanelView(3267): Configuration orientation changed
I/TimeManager(3267): receiver action = android.intent.action.CONFIGURATION_CHANGED
I/WorkActivity(19320): in onCreate...from=0 isConfingChanged=false
I/WindowBlurViewManager(3267): allowChangeBlurBackground
I/TimeManager(3267): notify time change. size = 2
I/TimeManager(3267): notify time change. size = 2
I/WindowBlurViewManager(3267): allowChangeBlurBackground
I/WorkActivity(19320): WorkActivity mSipBroadCastRecv got broadcast action=org.doubango.ngn.events.NgnRegistrationEventArgs.ACTION_REGISTRATION_CHANGED
I/WorkActivity(19320): WorkActivity mSipBroadCastRecv got broadcast action=org.doubango.ngn.events.NgnRegistrationEventArgs.ACTION_REGISTRATION_CHANGED
E/MY_TAG(3945): plugged changed1486628313398
E/MY_TAG(3945): plugged changed1486628330300
I/TimeManager(3267): notify time change. size = 2
E/MY_TAG(3945): plugged changed1486628373394
E/MY_TAG(3945): plugged changed1486628390461
I/TimeManager(3267): notify time change. size = 2
I/HwSystemManager(3625): HsmPackageManager:onConfigureChanged: zh_CN
W/ws000(13240): Application#onConfigurationChanged() is invoked!!!
...
I/HwLauncher(26780): Model onReceive intent=Intent { act=android.intent.action.CONFIGURATION_CHANGED flg=0x70000010 }
I/PanelView(3267): Configuration orientation changed
......
而事实是中间没有进行任何与语言时区修改有关的操作,又陷入了抓狂中……
一顿纠结之后,终于发现,在该activity的onCreate中判断某服务没有启动时,会跳转到一个splash页面启动服务,而该splash页面是竖屏的!
在menifest中修改该splash页面的orentation与后面的一致,ok问题解决。
<activity android:name="com.screens.SplashActivity"
android:screenOrientation="landscape" />
当然也可以重写Activity的onConfigurationChanged方法进行处理,这需要看具体情况。
希望能给遇到类似问题的朋友一点灵感·~
感谢网友的慷慨分享:
http://blog.csdn.net/u013951778/article/details/52612083