Android: SharedPreferences in integer value of BroadcastReceiver RadioButton not updating?

I have an action to change radioButton.

in oncreate method

     sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
     radioGroup = (RadioGroup)findViewById(R.id.radiogroup);
     radioGroup.setOnCheckedChangeListener(radioGroupOnCheckedChangeListener);

Implement an overridden method and get Radiobutton to maintain 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 sharePreference ...

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 that Receive the AlarmReceiver extends 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 also support the AndroidMainifest.xml file

  <receiver 
        android:name="AlarmReceiver" 
        android:process=":remote"
           />

The problem is onReceive .. with the first rule of the checked.exe field. The second time, if checkIndex is updated when the RadioButton changes, it returns the first value. The value does not seem to be updated ...

+4
source share
1 answer

Here AndroidMainifest.xml in the file changes the value of the receiver ...

 <receiver 
    android:name="AlarmReceiver" 
            />
0

Source: https://habr.com/ru/post/1531298/


All Articles