There is such a variable: Preferences preferences; In the game class, when the game ends do this:

game.tempGameScore = game.dropsGatchered; game.dropsGatchered = 0; iter.remove(); game.preferences.putInteger("Save", game.tempGameScore); game.preferences.flush(); 

In the class with the result I deduce:

  @Override public void render(float delta) { Gdx.gl.glClearColor(0f, 0f, 0f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); game.batch.begin(); game.batch.draw(bacgTexture, 0, 0, Drop.WIDTH, Drop.HEIGHT); if (game.tempGameScore != 0) { textFont.draw(game.batch, " " + game.preferences.getInteger("Save", game.tempGameScore), 800/2, 480/2); } else { game.tempGameScore = 0; textFont.draw(game.batch, " " + game.tempGameScore, 800/2, 480/2); } game.batch.end(); } 

The speed is saved and displayed, how to make the best result be saved between sessions?

    1 answer 1

    Try using Shared Preferences.
    Data will be stored between sessions.

    Using

     public class Calc extends Activity { public static final String PREFS_NAME = "MyPrefsFile"; @Override protected void onCreate(Bundle state){ super.onCreate(state); . . . // Restore preferences SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); boolean silent = settings.getBoolean("silentMode", false); setSilent(silent); } @Override protected void onStop(){ super.onStop(); // We need an Editor object to make preference changes. // All objects are from android.context.Context SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("silentMode", mSilentMode); // Commit the edits! editor.commit(); } } 

    Source - Data Storage - Storage Options