• 在 SoundSettings 里添加 tr69 CheckBoxPreference


    1. 在 sound_settings.xml里添加

        <CheckBoxPreference     
                android:key="tr69"
                android:title="@string/tr69"
                android:persistent="false"

                android:defaultValue="true"/>

    2. 在string.xml中添加

        <string name="tr69">TR69</string>


    3.在SoundSettings.java中添加

        private static final String KEY_TR69 = "tr69";
        private CheckBoxPreference mTr69;

        在onCreate(Bundle  savedInstanceState)中,

        添加

        mTr69 = (CheckBoxPreference) findPreference(KEY_TR69);
        mTr69.setPersistent(false);

        注: public void setPersistent (boolean persistent)

               Sets whether this Preference is persistent. When persistent, it stores its value(s) into the persistent SharedPreferences storage.

               SharedPreference

               Interface for accessing and modifying preference data returned by getSharedPreferences(String, int). For any particular set of

               preferences, there is a single instance of this class that all clients share. Modifications to the preferences must go through an

               SharedPreferences.Editor object to ensure the preference values remain in a consistent state and control when they are committed to

               storage. Objects that are returned from the various get methods must be treated as immutable by the application.

        此时, 编译执行./partChange

    此时, 打开虚拟机后, 由于defaultValue = "true", 所以是打勾的。

    点击tr69, 使其不打勾。 关机, 重新打开虚拟机后, 仍然是打勾的, 此时证明没有被保存。

        (1) 此时, sound_settings.xml中,

                android:persistant = "false";

                修改SoundSettings.java

                mTr69.setPersistant(true);

                重新编译, 使其不打勾。 关机, 重新打开虚拟机, 仍然是打勾的, 证明没有被保存。

              

         (2) 修改sound_settings.xml

                android:persitant= "true"

                修改 SoundSettings.java

                mTr69.setPerstant(false);

               

                重新编译。 关机, 重新打开虚拟机,不管操作打勾还是不打勾,重新打开时都是不打勾的。

          (3)

                修改sound_settings.xml

                 android:persistant="true".

                 修改SoundSettings.java

                 mTr69.setPersitant(true);

                

                重新编译, 使其不打勾。 关机, 重新打开虚拟机,不打勾, 证明已被保存。

          (4) sound_setting.xml中

                  android:persistant = "true"

                  修改SoundSettings.java

                  将mTr69.setPersistant()删去。

                  重新编译。  此时, 可以保存该 CheckBoxPreference的值。

         结论, Shared Preference是持久化存储的一种, 但 android:persistant必须要为 true才能保存。

        在SoundSettings中, 各个用来配置系统参数的Preference的 androidt:persistant 属性都为 false。

        所以, 不是用这里的preference来存储系统参数的。

        

  • 相关阅读:
    序列化结构体字段顺序 按照结构体的某个字段排序
    《领域驱动设计》:从领域视角深入仓储(Repository)的设计和实现
    操作系统上的进程 (最小 Linux; fork, execve 和 exit)
    PPM文件格式 Portable Pixmap Format)
    深度 | 字节跳动微服务架构体系演进
    Go 与 C 的桥梁:cgo 入门,剖析与实践
    您的时钟快了 建立私密连接
    os.Exit(123)
    在终端中显示图像
    StampedLock内部是基于CLH锁实现的,CLH是一种自旋锁,能够保证没有“饥饿现象”的发生,并且能够保证FIFO(先进先出)的服务顺序。
  • 原文地址:https://www.cnblogs.com/gavinwu/p/3105957.html
Copyright © 2020-2023  润新知