Skip to content

processHideSoftInputOnActivityDestroy里面的window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)会引起卡顿 #1835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
weiyfwork opened this issue May 23, 2025 · 0 comments
Assignees
Labels

Comments

@weiyfwork
Copy link

weiyfwork commented May 23, 2025

描述 Bug

听云报了一堆卡顿问题,定位在了processHideSoftInputOnActivityDestroy里面的window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)

  • AndroidUtilCode 的版本:1.31.1
  • 出现 Bug 的设备型号:小米 Redmi 50等一系列小米手机 见后面的截图
  • 设备的 Android 版本:Android 12 到 Android 15都有 见后面的截图

相关代码

以下代码中的:window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

private void processHideSoftInputOnActivityDestroy(final Activity activity, boolean isSave) {
        try {
            if (isSave) {
                Window window = activity.getWindow();
                final WindowManager.LayoutParams attrs = window.getAttributes();
                final int softInputMode = attrs.softInputMode;
                window.getDecorView().setTag(-123, softInputMode);
                window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
            } else {
                final Object tag = activity.getWindow().getDecorView().getTag(-123);
                if (!(tag instanceof Integer)) return;
                UtilsBridge.runOnUiThreadDelayed(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Window window = activity.getWindow();
                            if (window != null) {
                                window.setSoftInputMode(((Integer) tag));
                            }
                        } catch (Exception ignore) {
                        }
                    }
                }, 100);
            }
        } catch (Exception ignore) {
        }
    }

截图

听云报的卡顿信息
Image
系统分布
Image
手机型号分布
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants