我有一个小问题,每次我尝试更改程序中的首选项时,它们在活动中都不会改变,它们只是保持默认值。
public class Reciever extends BroadcastReceiver {
boolean smsOn = false;
String smsColor = new String ("Green");
Uri smsSound;
String smsVibrate = new String ("Normal");
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(arg0);
smsOn = pref.getBoolean(Preferences."PREF_SMS_ON", false);
smsColor = pref.getString(Preferences.SMS_PREF_COLOR, "Green");
smsSound = Uri.parse(pref.getString(Preferences.SMS_PREF_SOUND, "Silent"));
smsVibrate = pref.getString(Preferences.SMS_PREF_SOUND, "Normal");
//all variable remain default value verified through debugger
NotificationManager mNotificationManager = (NotificationManager) arg0.getSystemService(Context.NOTIFICATION_SERVICE);
if (arg1.getAction().equals(ACTION)){
if(smsOn == true){....... if checkbox is checked smsOn still remains false
}
优先活动类
public class Preferences extends PreferenceActivity implements OnPreferenceClickListener{
public static final String PREF_SMS_ON = "PREF_SMS_ON";
public static final String VIBRATE_ON_CALL1 = "VIBRATE_ON_CALL1";
public static final String SMS_PREF_COLOR = "SMS_PREF_COLOR";
public static final String SMS_PREF_SOUND = "SMS_PREF_SOUND";
public static final String SMS_PREF_VIB = "SMS_PREF_VIB";
}
xml文件(我只复制一个)
<CheckBoxPreference
android:key="PREF_SMS_ON"
android:title="SMS Notifications"
android:summary="Turn On SMS Notifications"
android:defaultValue="false">
</CheckBoxPreference>
我不明白它出了什么问题,看起来它应该对我有用