Android锁屏解锁卡顿优化——原理分析与GC回收( 三 )

好巧 , 报错也是因为Binder没有unBinder成功 , 与traceview的Binder耗时 , 以及systrace的GC耗时的信息都有千丝万缕的关系 , 也许就是问题的所在 , 接下来就是解决这个错误 , 并验证的时刻 。找到如下资料:
google Android Issue中有这个缺陷 , 缺陷详细信息在这里(Google Android Issue 2483) , Using getApplicationContext().bindService instead of just bindService on your activity solves the problem as it is using the higher level application context.先调用getApplicationContext()获取其所属的Activity的上下文环境才能正常bindService , 也就是在onCreate()方法中使用this.getApplicationContext().bindService([args…])就可以了,否则bindService将永远失败返回false 。那么就看log找到对应的地方 , 我们发现绑定binder的地方是用的getContext().Binder(xxxx),解绑的地方是用的getActivity().unBinder(xxx),我们通通换成getActivity().getApplicationContext().binder(xxx) (unBinder),编译push验证 , 查看log如下:
Line 2240: 01-21 15:29:12.629 1167 1325 I ActivityManager: Displayed com.android.settings/.SubSettings: +2s672ms [aosp]Android性能优化知识学习 , 获~可私信发送:“核心笔记”或“手册”即可获取!
五、文末成功优化了大约3秒的时间 , 虽然还感觉有卡顿 , 但是已经好很多 , 因为为了方便调试 , 编译的是userdebug版本 , 使用user版本后效果还有提升 , 算是能够过的去了!
更多性能优化(卡顿优化、UI优化、布局优化、稳定性优化、电量优化等)可前往私信哦 。





推荐阅读