title: How to refresh activity when I click on new button
body: <p>When I click on the new game button it doesn't refresh my game it still in the old one anyone can help me how to solve it. Here my code</p>
  
  <p><strong>Menu Game Class</strong></p>
  
  <pre><code>public class MenuScreen extends ListActivity {
  public static final String NEW_GAME = "new_game";
  
  /** Called when the activity is first created. */
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      final String[] ACTIVITY_CHOICES = new String[] {
              getString(R.string.menu_new_game),
              getString(R.string.menu_prefs)
          };
      setContentView(R.layout.activity_menu_screen);
      setListAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1,ACTIVITY_CHOICES));
      getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
      getListView().setTextFilterEnabled(true);
      OnItemClickListener myOnItemClickListener = new OnItemClickListener() {
  
          public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3){
              switch(arg2) {
              case 0:
                  startGame();
                  break;
              case 1:
                  startPrefs();
                  break;
              default: break;
              }
  
          }
      };
      getListView().setOnItemClickListener(myOnItemClickListener);
  }
  
  private void startGame() {
      Intent launchGame = new Intent(this, MainActivity.class);
      launchGame.putExtra("SENDER", "MenuScreen");
      startActivity(launchGame);
  }
  
  private void startPrefs() {
      Intent launchPrefs = new Intent(this, Setting.class);
      startActivity(launchPrefs);
  }}
  </code></pre>
  
  <p><strong>Play Game Class</strong></p>
  
  <pre><code>   public class MainActivity extends Activity {
      public static final String COME_FROM = "come_from";
      private int[] id_mc = new int[16];
      private Integer[][] img_mc = new Integer[16][2];
      private Button[] myMcs = new Button[16];
      private int mc_counter = 0;
      private int firstid = 0;
      private int secondid = 0;
      private Boolean mc_isfirst = false;
      private int correctcounter = 0;
      private TextView tFeedback;
      private MediaPlayer mp;
      private Boolean b_snd_inc, b_snd_cor;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Toast.makeText(this, "onCreate", Toast.LENGTH_SHORT).show();
          initGame();
      }
      private void initGame() {
          setContentView(R.layout.activity_main);
          SharedPreferences settings = getSharedPreferences("memoryPrefs", 0);
          b_snd_cor =settings.getBoolean("play_sound_when_correct", true);
          b_snd_inc =settings.getBoolean("play_sound_when_incorrect", true);      
          mc_counter = 0;
          firstid = 0;
          secondid = 0;
          mc_isfirst = false;
          correctcounter = 0; 
          tFeedback = (TextView) findViewById(R.id.mc_feedback);
          // setup button listeners
          Button startButton = (Button) findViewById(R.id.game_menu);
          startButton.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {
                  startMenu();
              }
          });     
          Button settingsButton = (Button) findViewById(R.id.game_settings);
          settingsButton.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {
                  startPrefs();
              }
          });
          // fill arrays with resources
          id_mc[0] = R.id.mc0;
          id_mc[1] = R.id.mc1;
          id_mc[2] = R.id.mc2;
          id_mc[3] = R.id.mc3;
          id_mc[4] = R.id.mc4;
          id_mc[5] = R.id.mc5;
          id_mc[6] = R.id.mc6;
          id_mc[7] = R.id.mc7;
          id_mc[8] = R.id.mc8;
          id_mc[9] = R.id.mc9;
          id_mc[10] = R.id.mc10;
          id_mc[11] = R.id.mc11;
          id_mc[12] = R.id.mc12;
          id_mc[13] = R.id.mc13;
          id_mc[14] = R.id.mc14;
          id_mc[15] = R.id.mc15;
          img_mc[0][0] = R.drawable.back1;
          img_mc[0][1] = R.drawable.ic_img1;
          img_mc[1][0] = R.drawable.back2;
          img_mc[1][1] = R.drawable.ic_img2;
          img_mc[2][0] = R.drawable.back3;
          img_mc[2][1] = R.drawable.ic_img3;
          img_mc[3][0] = R.drawable.back4;
          img_mc[3][1] = R.drawable.ic_img4;
          img_mc[4][0] = R.drawable.back5;
          img_mc[4][1] = R.drawable.ic_img5;
          img_mc[5][0] = R.drawable.back6;
          img_mc[5][1] = R.drawable.ic_img6;
          img_mc[6][0] = R.drawable.back7;
          img_mc[6][1] = R.drawable.ic_img7;
          img_mc[7][0] = R.drawable.back8;
          img_mc[7][1] = R.drawable.ic_img8;
          img_mc[8][0] = R.drawable.back1;
          img_mc[8][1] = R.drawable.ic_img1;
          img_mc[9][0] = R.drawable.back2;
          img_mc[9][1] = R.drawable.ic_img2;
          img_mc[10][0] = R.drawable.back3;
          img_mc[10][1] = R.drawable.ic_img3;
          img_mc[11][0] = R.drawable.back4;
          img_mc[11][1] = R.drawable.ic_img4;
          img_mc[12][0] = R.drawable.back5;
          img_mc[12][1] = R.drawable.ic_img5;
          img_mc[13][0] = R.drawable.back6;
          img_mc[13][1] = R.drawable.ic_img6;
          img_mc[14][0] = R.drawable.back7;
          img_mc[14][1] = R.drawable.ic_img7;
          img_mc[15][0] = R.drawable.back8;
          img_mc[15][1] = R.drawable.ic_img8;
          //Collections.shuffle(Arrays.asList(img_mc));
          for (int i = 0; i &lt; 16; i++) {
              myMcs[i] = (Button) findViewById(id_mc[i]);
              myMcs[i].setBackgroundResource(img_mc[i][0]);
              myMcs[i].setOnClickListener(new View.OnClickListener() {
                  public void onClick(View view) {
                      int i = 0;
                      for (int n = 0; n &lt; 16; n++) {
                          if (id_mc[n] == view.getId())
                              i = n;
                      }
                      doClickAction(view, i);
                  }
              });
          }
      }
      private void doClickAction(View v, int i)
      {
          v.setBackgroundResource(img_mc[i][1]);
          mc_isfirst = !mc_isfirst;
  
          // disable all buttons
          for (Button b : myMcs) {
              b.setEnabled(false);
          }
          if (mc_isfirst) {
              // turning the first card
              firstid = i;
              // re enable all except this one
              for (Button b : myMcs) {
                  if (b.getId() != firstid) {
                      b.setEnabled(true);
                  }
              }
          } else {
              // turning the second card
              secondid = i;   
              doPlayMove();
          }
      }
      private void doPlayMove() {
          mc_counter++;
          if (img_mc[firstid][1] - img_mc[secondid][1] == 0) {
              //correct
              if (b_snd_cor) playSound(R.raw.correct);
              waiting(200);
              myMcs[firstid].setVisibility(View.INVISIBLE);
              myMcs[secondid].setVisibility(View.INVISIBLE);
              correctcounter++;
          } else {
              //incorrect
              if (b_snd_inc) playSound(R.raw.incorrect);
              waiting(400);
          }
          // reenable and turn cards back
          for (Button b : myMcs) {
              if (b.getVisibility() != View.INVISIBLE) {
                  b.setEnabled(true);
                  b.setBackgroundResource(R.drawable.memory_back);
                  for (int i = 0; i &lt; 16; i++) {
                      myMcs[i].setBackgroundResource(img_mc[i][0]);
                  }
              }
          }
          tFeedback.setText("" + correctcounter + " / " + mc_counter);
          if (correctcounter &gt; 7) {
              Intent iSc = new Intent(getApplicationContext(), Scoreboard.class);
              iSc.putExtra("com.gertrietveld.memorygame.SCORE", mc_counter);
              startActivity(iSc);
          }
      }
      public void playSound(int sound) {
          mp = MediaPlayer.create(this, sound);
          mp.setVolume((float).5,(float).5);
          mp.start();
          mp.setOnCompletionListener(new OnCompletionListener() {
              public void onCompletion(MediaPlayer mp) {
                  mp.release();
              }
          });
      }
      public static void waiting(int n) {
          long t0, t1;
          t0 = System.currentTimeMillis();
          do {
              t1 = System.currentTimeMillis();
          } while ((t1 - t0) &lt; (n));
      }
      private void startMenu() {
          Intent launchMenu = new Intent(this, MenuScreen.class);
          launchMenu.putExtra(COME_FROM,"PlayGame");
          startActivity(launchMenu);
      }
      private void startPrefs() {
          Intent launchPrefs = new Intent(this, Setting.class);
          startActivity(launchPrefs);
      }
      ////////////////////////////////    
      @Override
      protected void onRestart() {
          super.onRestart();
              Toast.makeText(this, "onRestart-sender is " , Toast.LENGTH_SHORT).show();
      }
  </code></pre>
  
  <p><strong>Setting Class</strong></p>
  
  <p>When the users setting they have option to disable the sound, after they disable it has two buttons: save back to game and save back to menu. But it doesn't do anything after click these two button. It works when i close the app and kill it then open again what i have set up in setting working fine.</p>
  
  <pre><code>  public class Setting extends Activity {
          private CheckBox ch_sound_correct, ch_sound_incorrect;
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_setting);
              ch_sound_correct = (CheckBox) findViewById(R.id.ch_sound_correct);
              ch_sound_incorrect = (CheckBox) findViewById(R.id.ch_sound_incorrect);
  
  
              Button saveButtonMenu = (Button) findViewById(R.id.save_prefs);
              saveButtonMenu.setOnClickListener(new View.OnClickListener() {
                  public void onClick(View v) {
                      Intent launchMenu = new Intent(getBaseContext(), MenuScreen.class);
                      setPreferences(launchMenu);
                  }
              });
  
              Button saveButtonGame = (Button) findViewById(R.id.save_game);
              saveButtonGame.setOnClickListener(new View.OnClickListener() {
                  public void onClick(View v) {
                      Intent launchGame = new Intent(getBaseContext(), MainActivity.class);
                      launchGame.putExtra("SENDER","Settings");   
                      setPreferences(launchGame);
                  }
              });
  
              getPreferences();
          }
          private void getPreferences()
          {
  
              SharedPreferences settings = getSharedPreferences("memoryPrefs", 0);
              ch_sound_correct.setChecked(settings.getBoolean("play_sound_when_correct", true));
              ch_sound_incorrect.setChecked(settings.getBoolean("play_sound_when_incorrect", true));
  
          }
  
          private void setPreferences(Intent theIntent)
          {
              SharedPreferences settings = getSharedPreferences("memoryPrefs", 0);
              SharedPreferences.Editor prefeditor = settings.edit();
              prefeditor.putBoolean("play_sound_when_correct", ch_sound_correct.isChecked());
              prefeditor.putBoolean("play_sound_when_incorrect", ch_sound_incorrect.isChecked());
              prefeditor.commit();
  
              //Toast.makeText(this, "setPreferences",Toast.LENGTH_LONG);
  
              startActivity(theIntent);
  
          }
      }
  </code></pre>