InputManagerService异常DeadObjectException的解决思路

最近维护到一个应用程序的代码,在某个activity页面中,页面只要打开持续一段时间(区分手机设备,htc的部分时间能持续半个小时以上不挂,samsung的手机有的40秒不到就挂,有的手机甚至是10秒中就会挂)。

 

查看后台抛出的异常信息如下:

 

W/InputManagerService(163): Session failed to close due to remote exception
W/InputManagerService(163): android.os.DeadObjectException
W/InputManagerService(163): 	at android.os.BinderProxy.transact(Native Method)
W/InputManagerService(163): 	at com.android.internal.view.IInputMethodSession$Stub$Proxy.finishSession(IInputMethodSession.java:346)
W/InputManagerService(163): 	at com.android.server.InputMethodManagerService.finishSession(InputMethodManagerService.java:944)
W/InputManagerService(163): 	at com.android.server.InputMethodManagerService.clearCurMethodLocked(InputMethodManagerService.java:955)
W/InputManagerService(163): 	at com.android.server.InputMethodManagerService.onServiceDisconnected(InputMethodManagerService.java:972)
W/InputManagerService(163): 	at android.app.LoadedApk$ServiceDispatcher.doDeath(LoadedApk.java:1069)
W/InputManagerService(163): 	at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1083)
W/InputManagerService(163): 	at android.os.Handler.handleCallback(Handler.java:587)
W/InputManagerService(163): 	at android.os.Handler.dispatchMessage(Handler.java:92)
W/InputManagerService(163): 	at android.os.Looper.loop(Looper.java:130)
W/InputManagerService(163): 	at com.android.server.ServerThread.run(SystemServer.java:559)

异常并不是应用本身抛出来的,而且出错的activity在AndroidManifest.xml中有设置android:windowSoftInputMode="stateAlwaysHidden",也就是软键盘恒定是隐藏的,并不涉及input相关的内容。

 

问题原因无法定位,上网各种google,搜索出来的结果无外乎类似于下面两种的说明:

(1)When the remote process gets killed by the OS,then you get a DeadObjectException. 

      Any process might get killed by the OS depending on system requirements.

(2)It seems like I've got a low memory issue in my App... 

       Can it be the reason why my IME process run away ? 

 

也就是说,网上并没有直接解决问题的方法,搜索的话根本不可能得到直接的答案。

无奈,只能将出错的activity的代码一行行的读,希望找到问题的原因所在:

最终发现activity中有用到opengl的东东,且有如下代码:

 

mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);

 这一行代码怎么看也不会有问题,但是仔细查看以下相关文档的说明发现有:(http://gjhappyyy.iteye.com/blog/1298729)

OpenGl ES关于渲染方式有以下两种:

 

RENDERMODE_CONTINUOUSLY和RENDERMODE_WHEN_DIRTY。

默认渲染方式为RENDERMODE_CONTINUOUSLY,这两种渲染的含义是:

RENDERMODE_CONTINUOUSLY:渲染器会不停地渲染场景,

RENDERMODE_WHEN_DIRTY:只有在创建和调用requestRender()时才会刷新。

一般设置为RENDERMODE_WHEN_DIRTY方式,这样不会让CPU一直处于高速运转状态,提高手机电池使用时间和软件整体性能。

 

 

也就是说activity页面在开着的时候,即使不做任何操作,手机的CPU等资源也是处于高速运转的状态,意味着有可能会耗掉其他app所需要的资源,从而触发其他应用导致InputManagerService的异常信息。

尝试将属性修改为GLSurfaceView.RENDERMODE_WHEN_DIRTY,测试:发现问题解决。

 

总结:

对于InputManagerService抛出的android.os.DeadObjectException相关异常,应该仔细检查出现异常的场景是否有大量使用cpu或者消耗内存的代码,而非找现成的答案。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值