1、界面A启动界面B,按返回键,界面B执行完onPause,会延迟10秒调用onStop和onDestroy
分析发现,界面A有一个用RadioGroup实现的底部导航栏,这个RadioGroup的子项是一个继承自RadioButton的自定义view。在这个自定义的RadioButton的onDraw方法里主要绘制了一排文字,即导航栏标题。然后再调用setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom)方法为文字加上一个icon。
经反复测试,延迟10秒调用onStop和onDestroy的原因就出在这个setCompoundDrawables方法上面。
然而具体原因还未得知,对着源码一脸懵逼。但是我感觉可能会和setCompoundDrawables方法最后连续调用的几个方法有关:
public void setCompoundDrawables(@Nullable Drawable left, @Nullable Drawable top,
@Nullable Drawable right, @Nullable Drawable bottom) {
Drawables dr = mDrawables;
...
resetResolvedDrawables();
resolveDrawables();
applyCompoundDrawableTint();
invalidate();
requestLayout();
}
这里我不知道为什么会先调用invalidate(),再调用requestLayout()
2、Material Design包提供的TabLayout,初始化时调用TabLayout.Tab.setCustomView方法设置一个自定义view。当我试着监听这个view的onTouch方法时发现,并没有接收到ACTION_UP和ACTION_CANCEL的事件。查看TabLayout源码也没有发现在哪儿拦截掉了事件。
懵逼。