title: Toggle Button returns after restarting the application
body: <p>I have recyclerView and I have like 5 cardView with toggle buttons on each of them so when i click on them they work perfectly lets say (on,off) but the problem is when i restart the application this toggle buttons that i decided to be on goes to be off i tried with sharedpereference but it didn't worked so here is my code can someone help and thanks</p>
  
  <pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyHolder&gt;{
  
  Context c;
  String[] players;
  String[] positions;
  int[] images;
  
  
  
  
  
  public MyAdapter(Context ctx,String[] players,String[] positions,int[] images)
  {
      this.c=ctx;
      this.players=players;
      this.positions=positions;
      this.images=images;
  
  }
  @Override
  public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.model,null);
  
      MyHolder holder=new MyHolder(v);
      SharedPreferences sharedPrefs = c.getSharedPreferences("com.example.xyz", MODE_PRIVATE);
      holder.fav.setChecked(sharedPrefs.getBoolean("NameOfThingToSave", true));
      return holder;
  }
  
  
  @Override
  public void onBindViewHolder(final MyHolder holder, final int position) {
  
  
  
      holder.nameTxt.setText(players[position]);
      holder.posTxt.setText(positions[position]);
      holder.img.setImageResource(images[position]);
      // holder.fav.setChecked(false);
  
    // holder.fav.setBackgroundDrawable(ContextCompat.getDrawable(c, R.drawable.star_off));
      holder.fav.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              if (holder.fav.isChecked())
              {
                  SharedPreferences.Editor editor = c.getSharedPreferences("com.example.xyz", MODE_PRIVATE).edit();
                  editor.putBoolean("NameOfThingToSave", true);
                  editor.commit();
              }
              else
              {
                  SharedPreferences.Editor editor = c.getSharedPreferences("com.example.xyz", MODE_PRIVATE).edit();
                  editor.putBoolean("NameOfThingToSave", false);
                  editor.commit();
              }
              if (isChecked)
                  holder.fav.setBackgroundDrawable(ContextCompat.getDrawable(c,R.drawable.star_light));
              else
                  holder.fav.setBackgroundDrawable(ContextCompat.getDrawable(c, R.drawable.star_off));
          }
      });
  
  
      holder.setItemClickListener(new ItemClickListener() {
          @Override
          public void onItemClick(View v, int pos) {
  
              Intent i=new Intent(c,DetailActivity.class);
  
              i.putExtra("Name",players[position]);
              i.putExtra("Position",positions[position]);
              i.putExtra("Image",images[position]);
  
              c.startActivity(i);
  
          }
      });
  
  }
  
  @Override
  public int getItemCount() {
      return players.length;
  }
  </code></pre>