Android 12.0 急救信息页面 添加信息时-横竖屏切换头像无法保存

文章讨论了在急救应用中,头像在横竖屏切换时未保存的问题。开发者在`EmergencyNamePreference`类的`onSaveInstanceState`方法中修复了对话框显示状态判断,确保数据在屏幕旋转时正确保存。涉及到Bitmap存储和临时文件操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

介绍

在设置菜单的-安全和紧急情况-打开急救信息中-用户选择姓名拍好头像后,进行横竖屏操作,头像被重新刷新了没有保存,对于横竖屏的切换保存数据,我们考虑的一般会想到Activity中如下的两个方法

public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState)
public void onRestoreInstanceState(Bundle savedInstanceState, PersistableBundle persistentState)

分析

我们在onSaveInstanceState中埋log调用的方法中也一样发现getDialog().isShowing()这个不满足条件判断所以导致保存数据失败

路径:vendor/mediatek/proprietary/packages/apps/EmergencyInfo/src/com/android/emergency/preferences/EmergencyNamePreference.java

        @Override
        public void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
            getEmergencyNamePreference().onSaveInstanceState(outState);
        }

修改

找打对应路径

路径:vendor/mediatek/proprietary/packages/apps/EmergencyInfo/src/com/android/emergency/preferences/EmergencyNamePreference.java

    public void onSaveInstanceState(Bundle outState) {
//*/soda water.20230922 Save a temp user photo
        if (getDialog() != null
/*/
        if (getDialog() != null && getDialog().isShowing()
//*/
                && mEditUserPhotoController != null) {
            // Bitmap cannot be stored into bundle because it may exceed parcel limit
            // Store it in a temporary file instead
            File file = mEditUserPhotoController.saveNewUserPhotoBitmap();
            if (file != null) {
                outState.putString(KEY_SAVED_PHOTO, file.getPath());
            }
        }
        if (mWaitingForActivityResult) {
            outState.putBoolean(KEY_AWAITING_RESULT, mWaitingForActivityResult);
        }
    }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不太正常的移动开发工程师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值