我目前正在开发一个应用程序,在该应用程序中,用户将看到一系列列表,单击每个列表,用户将被带到基于他的选择的另一个列表。现在,为了记住用户在每个屏幕上做了什么,我在我的共享首选项中插入了一系列字符串。事实证明,由于我的应用程序有大约7个8个选择屏幕,我的整个代码只是与从共享首选项中读取和写入密钥纠缠在一起。
air_conditioning = Session.getBoolean(SELL_AIR_CONDITIONINING) ? "1" : "0";
power_steering = Session.getBoolean(SELL_POWER_STEERING) ? "1" : "0";
power_locks = Session.getBoolean(SELL_POWER_LOCKS) ? "1" : "0";
power_mirrors = Session.getBoolean(SELL_POWER_MIRROR) ? "1" : "0";
keyless_entry = Session.getBoolean(SELL_KEYLESS_ENTRY) ? "1" : "0";
cruise_control = Session.getBoolean(SELL_CRUISE_CONTROL) ? "1" : "0";
navigation_system = Session.getBoolean(SELL_NAVIGATION_SYSTEM) ? "1" : "0";
abs = Session.getBoolean(SELL_ABS) ? "1" : "0";
am_fm_radio = Session.getBoolean(SELL_FM_AM_RADIO) ? "1" : "0";
cassette_player = Session.getBoolean(SELL_CASSETE_PLAYER) ? "1" : "0";
cd_player = Session.getBoolean(SELL_CD_PLAYER) ? "1" : "0";
sun_roof = Session.getBoolean(SELL_SUN_ROOF) ? "1" : "0";
alloy_rims = Session.getBoolean(SELL_ALLOW_RIMS) ? "1" : "0";所以这基本上就是我的整个代码,看起来很难看,容易出错,而且不太容易维护。我正在寻找在这种情况下对我有用的任何解决方案。
亲切的问候
发布于 2012-12-12 12:31:01
不要使用SharedPreferences。使用Intent%s并通过Bundle传递状态。
https://stackoverflow.com/questions/13832740
复制相似问题