title: How to implement SharedPreferences?
body: <p>How should I implement SharedPreferences  inside <code>updateRunning(List&lt;TouchEvent&gt; touchEvents, float deltaTime)</code> in <code>GameScreen</code>?</p>
  
  <pre><code>SharedPreferences settings = getSharedPreferences("Prefs", 0);
  SharedPreferences.Editor editor = settings.edit();
  editor.putInt("highscore", var);
  editor.commit();
  </code></pre>
  
  <p><strong>GameScreen.java</strong></p>
  
  <pre><code>package com.m.robotgame;
  
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Scanner;
  
  import android.app.Activity;
  import android.content.SharedPreferences;
  import android.graphics.Color;
  import android.graphics.Paint;
  
  import com.m.framework.Game;
  import com.m.framework.Graphics;
  import com.m.framework.Image;
  import com.m.framework.Input.TouchEvent;
  import com.m.framework.Screen;
  
  public class GameScreen extends Screen {
  
      enum GameState {
          Ready, Running, Paused, GameOver
      }
  
      GameState state = GameState.Ready;
  
      private static Robot robot;
  
      public static int height = 0, highscore;
      public int score;
  
      private Image currentSprite, character;
  
      private ArrayList&lt;Tile&gt; tilearray = new ArrayList&lt;Tile&gt;();
  
      Paint paint;
  
      public GameScreen(Game game) {
          super(game);
          robot = new Robot();
          character = Assets.character;
          paint = new Paint();
          paint.setTextSize(25);
          paint.setTextAlign(Paint.Align.CENTER);
          paint.setAntiAlias(true);
          paint.setColor(Color.WHITE);
  
      }
  
      @Override
      public void update(float deltaTime) {
          List&lt;TouchEvent&gt; touchEvents = game.getInput().getTouchEvents();
          if (state == GameState.Ready)
              updateReady(touchEvents);
  
          if (state == GameState.Running)
              updateRunning(touchEvents, deltaTime);
  
          if (state == GameState.Paused)
              updatePaused(touchEvents);
  
          if (state == GameState.GameOver)
              updateGameOver(touchEvents);
      }
  
      private void updateReady(List&lt;TouchEvent&gt; touchEvents) {
          if (touchEvents.size() &gt; 0)
              state = GameState.Running;
      }
  
      private void updateRunning(List&lt;TouchEvent&gt; touchEvents, float deltaTime) {
  
          //Here I would like to have SharedPreferences
  
          int len = touchEvents.size();
  
          for (int i = 0; i &lt; len; i++) {
              TouchEvent event = touchEvents.get(i);
              if (event.type == TouchEvent.TOUCH_DOWN) {
                  if (event.x &gt; 80) {
                      ...
                  }
                  if (event.x &lt; 20) {
                      ...
                  }
              }
  
              if (event.type == TouchEvent.TOUCH_UP) {
                  ...
  
                  if (inBounds(event, 220, 0, 40, 40)) {
                      ...
                  }
  
              }
  
          }
  
          if (robot.getCenterY() &gt; 200) {
              ...
          }
      }
  
  
      private void updatePaused(List&lt;TouchEvent&gt; touchEvents) {
          ...
      }
  
      private void updateGameOver(List&lt;TouchEvent&gt; touchEvents) {
          ...
      }
  
      private void updateTiles() {
          ...
      }
  
      @Override
      public void paint(float deltaTime) {
          ...
      }
  
      private void nullify() {
          ...
      }
  
      private void drawReadyUI() {
          ...
      }
  
      private void drawRunningUI() {
          ...
      }
  
      private void drawPausedUI() {
          ...
      }
  
      private void drawGameOverUI() {
          ...
      }
  
      @Override
      public void pause() {
  
          if (state == GameState.Running)
          state = GameState.Paused;
      }
  
      @Override
      public void resume() {
  
          if (state == GameState.Paused)
          state = GameState.Running;
      }
  
      @Override
      public void dispose() {
  
      }
  
      private void goToMenu() {
          game.setScreen(new MainMenuScreen(game));
      }
  
      public static Robot getRobot() {
          return robot;
      }
  
  }
  </code></pre>
  
  <p>Since I'm beginner in Android and Java it would be very helpful if you could write actual code that is required in order for this to work, because comments like "You should do this..." unfortunately doesn't mean a lot to me. Thank you.</p>