I have Activity to change the radioButton.
in oncreate Method
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
radioGroup = (RadioGroup)findViewById(R.id.radiogroup);
radioGroup.setOnCheckedChangeListener(radioGroupOnCheckedChangeListener);
Implement the overridden method and get the Radiobutton save the sharedpreference
RadioGroup.OnCheckedChangeListener radioGroupOnCheckedChangeListener =
new RadioGroup.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton checkedRadioButton = (RadioButton)radioGroup.findViewById(checkedId);
int checkedIndex = radioGroup.indexOfChild(checkedRadioButton);
savePreferences("remaindertype_toggle_value",checkedIndex);
Log.e("Chenge", String.valueOf(checkedIndex)); // here the get proper value of checkdIndex
}};
Implement the sharePreference method...
private void savePreferences(String key, int data) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(key, data);
editor.commit();
Log.e("Chengeinside", String.valueOf(value));// Here also get the proper value of the data..
}
now when the Receive the AlarmReceiver extend BroadcastReceiver
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(context);
TypeToggleValue = sharedPreferences.getInt(RemainderType_Toggle, 0);
Log.e("AppToggleValue", String.valueOf(TypeToggleValue));// here when first time run the application get the proper value but change the value and secound time get the value its does not updated
}
I am also maintain the AndroidMainifest.xml file
<receiver
android:name="AlarmReceiver"
android:process=":remote"
/>
The issue is in onReceive.. the first time the "checkedIndex" field is correct. The second time, if checkedIndex is updated when radioButton change , however, it returns the first value. The value does not seem to get updated...
Here AndroidMainifest.xml in the file change the receiver value...
<receiver
android:name="AlarmReceiver"
/>