title: How to save state of checked radio button in android studio
body: <p>I am using three radio buttons in radio group to select one of theme to perform the theme selection(default ,Light and Dark theme). but when I restart app there will be no one selected . How can I save the state of checked radio button and when I restart the app last checked radio button remain checked. i am attaching screenshot and code here, Please can anyone help me in detail because i am new in android studio.
  (<a href="https://i.stack.imgur.com/T12yH.jpg" rel="nofollow noreferrer">Light Theme Selected</a>) (<a href="https://i.stack.imgur.com/apesX.jpg" rel="nofollow noreferrer">Dark Theme Selected</a>) (<a href="https://i.stack.imgur.com/rMNE0.jpg" rel="nofollow noreferrer">After restarting app</a>)</p>
  <p>xml</p>
  <pre><code>&lt;RadioGroup
                  android:id=&quot;@+id/radio_group&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:orientation=&quot;horizontal&quot;
                  android:layout_gravity=&quot;center&quot;
                  android:layout_marginRight=&quot;50dp&quot;
                  android:layout_marginLeft=&quot;50dp&quot;
                  android:layout_marginTop=&quot;10dp&quot;
                  android:layout_marginBottom=&quot;20dp&quot;&gt;
  
                  &lt;RadioButton
                      android:id=&quot;@+id/system&quot;
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:text=&quot;Default&quot;
                      android:layout_weight=&quot;1&quot;
                      android:gravity=&quot;center&quot;
                      app:backgroundTint=&quot;@null&quot;
                      android:button=&quot;@color/transparent&quot;
                      android:background=&quot;@drawable/radio_btn_selector&quot;
                      android:textColor=&quot;@drawable/radio_btn_text_color&quot;
                      android:elevation=&quot;4dp&quot;
                      android:padding=&quot;10dp&quot;
                      android:textSize=&quot;13dp&quot;
                      android:textAllCaps=&quot;true&quot;
                      android:layout_marginTop=&quot;10dp&quot;
                      android:layout_marginBottom=&quot;10dp&quot;
                      android:layout_marginLeft=&quot;5dp&quot;/&gt;
                  &lt;RadioButton
                      android:id=&quot;@+id/light&quot;
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:text=&quot;Light&quot;
                      android:layout_weight=&quot;1&quot;
                      android:gravity=&quot;center&quot;
                      app:backgroundTint=&quot;@null&quot;
                      android:button=&quot;@color/transparent&quot;
                      android:background=&quot;@drawable/radio_btn_selector&quot;
                      android:textColor=&quot;@drawable/radio_btn_text_color&quot;
                      android:elevation=&quot;4dp&quot;
                      android:padding=&quot;10dp&quot;
                      android:textSize=&quot;13dp&quot;
                      android:textAllCaps=&quot;true&quot;
                      android:layout_marginTop=&quot;10dp&quot;
                      android:layout_marginBottom=&quot;10dp&quot;
                      android:layout_marginLeft=&quot;5dp&quot;/&gt;
                  &lt;RadioButton
                      android:id=&quot;@+id/dark&quot;
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:text=&quot;Dark&quot;
                      android:layout_weight=&quot;1&quot;
                      android:gravity=&quot;center&quot;
                      app:backgroundTint=&quot;@null&quot;
                      android:button=&quot;@color/transparent&quot;
                      android:background=&quot;@drawable/radio_btn_selector&quot;
                      android:textColor=&quot;@drawable/radio_btn_text_color&quot;
                      android:elevation=&quot;4dp&quot;
                      android:padding=&quot;10dp&quot;
                      android:textSize=&quot;13dp&quot;
                      android:textAllCaps=&quot;true&quot;
                      android:layout_marginTop=&quot;10dp&quot;
                      android:layout_marginBottom=&quot;10dp&quot;
                      android:layout_marginLeft=&quot;5dp&quot;
                      android:layout_marginRight=&quot;5dp&quot;/&gt;
  
              &lt;/RadioGroup&gt;
  </code></pre>
  <p>Java Code in Fragment</p>
  <pre><code> @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View view = inflater.inflate(R.layout.fragment_appearance_bottom_sheet, container, false);
  
         // materialButtonToggleGroup = view.findViewById(R.id.btn_group);
         radioGroup = view.findViewById(R.id.radio_group);
  
  
          radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(RadioGroup radioGroup, int i) {
                  switch(i) {
                      case R.id.system:
  
                          break;
                      case R.id.light:
                          AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                          break;
                      case R.id.dark:
                          AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                          break;
                  }
              }
          });
  
          return  view;
      }
  </code></pre>