Where to store Android preference keys?

前端 未结 7 890
孤城傲影
孤城傲影 2020-12-23 11:33

When I create preference activity I define all preferences in xml file. Every preference has a key defined in this xml. But when I access preference I write:



        
相关标签:
7条回答
  • 2020-12-23 12:03

    What about using a helper class to hide the getString() - instantiate the helper once in each activity or service. For example:

    class Pref {
    
        final String smsEnable_pref;
        final String interval_pref;
        final String sendTo_pref;
        final String customTemplate_pref;
        final String webUrl_pref;
    
        Pref(Resources res) {       
             smsEnable_pref = res.getString(R.string.smsEnable_pref);
             interval_pref = res.getString(R.string.interval_pref);
             sendTo_pref = res.getString(R.string.sendTo_pref);
             customTemplate_pref = res.getString(R.string.customTemplate_pref);
             webUrl_pref = res.getString(R.string.webUrl_pref);
        }
    }
    
    0 讨论(0)
提交回复
热议问题