title: How to store users progress in my game
body: <p>I am new to android so in the interest of learning i made myself a simple game where the user finds an image in one activity "<em>scene1</em>" then once they press the image it moves to the next activity "<em>scene2</em>", All works fine. What i want to do is save what level the user gets to so they can continue the next time they start the game by clicking a load save data button for example. </p>
  
  <p>I have looked into shared prefs and writing to a file in the internal storage but i can not seem to get my head around it :(  It would be really helpful if you could offer me some help and get me moving in the right direction :)</p>
  
  <p>Below is the code i use for each level. </p>
  
  <pre><code>public class scene1 extends Activity implements OnClickListener {
  
  private CountDownTimer countDownTimer;
  private boolean timerHasStarted = false;
  private Button startB;
  public TextView text;
  private final long startTime = 20 * 1000;
  private final long interval = 1 * 1000;
  
  @Override
  public void onBackPressed() {
      new AlertDialog.Builder(this)
      .setIcon(android.R.drawable.ic_dialog_alert)
      .setTitle("FindIt")
      .setMessage("Exit to main menu?")
      .setPositiveButton("Yes", new DialogInterface.OnClickListener()
  {
      @Override
      public void onClick(DialogInterface dialog, int which) {
          finish();    
      }
  
  })
  .setNegativeButton("No", null)
  .show();
  }
  
  ImageButton imageButton;
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  
      startB = (Button) this.findViewById(R.id.button);
      startB.setOnClickListener(this);
      text = (TextView) this.findViewById(R.id.timer);
      countDownTimer = new MyCountDownTimer(startTime, interval);
      text.setText(text.getText() + String.valueOf(startTime/1000));
      }
  
      @Override
      public void onClick(View v) {
      startB.setVisibility(View.INVISIBLE);   
      if (!timerHasStarted) {
      countDownTimer.start();
      timerHasStarted = true;
      startB.setText("STOP");
      } else {
      countDownTimer.cancel();
      timerHasStarted = false;
      startB.setText("RESTART");
      }
      }
  
  
      public class MyCountDownTimer extends CountDownTimer {
      public MyCountDownTimer(long startTime, long interval) {
      super(startTime, interval);
      }
  
      @Override
      public void onFinish() {
          Intent intent = new Intent(scene1.this, timeUp.class);
          scene1.this.startActivity(intent);
          finish();
              }
  
      @Override
      public void onTick(long millisUntilFinished) {
      text.setText("" + millisUntilFinished/1000);
  
  
      addListenerOnButton();
  
  }
  
  public void addListenerOnButton() {
  
      imageButton = (ImageButton) findViewById(R.id.it);
  
      imageButton.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
  
             Toast.makeText(scene1.this,
              "You found It!", Toast.LENGTH_LONG).show();
  
             Intent intent = new Intent(scene1.this, scene2.class);
             scene1.this.startActivity(intent);
             android.os.Process.killProcess(android.os.Process.myPid());
             finish();
  
          }
  
      }); 
  }
  
  }
  }
  </code></pre>