开发者

Added preferences dynamically that will last over sessions

开发者 https://www.devze.com 2023-04-09 20:10 出处:网络
I have preference defined in xml, and I do this addPreferencesFromResource(R.xml.preferences1); to create the pref activity. But in code (dynamically) at runtime somethimes(depends on busyness logic)

I have preference defined in xml, and I do this addPreferencesFromResource(R.xml.preferences1); to create the pref activity. But in code (dynamically) at runtime somethimes(depends on busyness logic) I add more items like this

CheckBoxPreference c=new CheckBoxPreference(this);
            c.setKey("asdasd");
            c.setTitle("asd");
            getPreferenceScreen().addPreference(c);

This works great and everything is fine(the state is sa开发者_开发技巧ved corectlly and it stays persistent) until I restart the phone. When I restart the phone this newly added item is lost. And only items from the xml file are shown in the prefereceActivity.

My question is what should I do to have this items even when the user restart the phone.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号