Best way to update checkbox prefefences

谁都会走 提交于 2019-12-12 05:39:11

问题


I was coding a clock for android. For it, i set a function which updates screen 1 time each a second, so my program can consume a lot of resources, and my objective is to add a checkbox preference, consuming the less resources as I can.

Then, my question is: I have seen some ways to update preferences with onSharedPreferenceChangeListener for example... Which is the way which consumes less system resources? How should I implement it to my code?


回答1:


if you are using a PreferenceActivity you can implement the OnPreferenceClickListener set a listener on the checkbox then in your onPreferenceClick method with the key you set for the box and do what you need to do with it

@Override
public boolean onPreferenceClick(Preference preference) {
    if (preference.getKey().equals("schedulestart")) {
        showDialog(0);
    } else if (preference.getKey().equals("schedulestop")) {
        showDialog(1);
    } else if (preference.getKey().equals("priority")) {
        // Reset unread count when switching mailboxes. They might differ.
        getPreferenceManager().getSharedPreferences().edit().putInt("unreadcount", 0).commit();
    }
    return true;
}


来源:https://stackoverflow.com/questions/10518667/best-way-to-update-checkbox-prefefences

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!