问题
在华为系列机型测试apk时,在BActivity定义的popupWindow跳转至AActivity时,出现长时间黑屏,或者ANR事件(长时间卡顿无响应)。
解决
在popupWindow的onDismiss()中,界面恢复时WindowManager.LayoutParams.alpha设置为1,此时将WindowManager.LayoutParams.FLAG_DIM_BEHIND标志清除,具体代码示例如下:
private void showPopup(PopupWindow popupWindow) {
WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
// 开启 popup 时界面透明
lp.alpha = 0.5f;
mActivity.getWindow().setAttributes(lp);
// 设置弹窗背景视图变暗
mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
popupWindow.showAtLocation(mLlMain, Gravity.BOTTOM, 0, 0);
// popup 退出时界面恢复
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
lp.alpha = 1f;
mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
mActivity.getWindow().setAttributes(lp);
}
});
}