0
\$\begingroup\$

I am trying to save a username for game in preferences (first time user enters the game, registration screen shows up, and after that whenever user enters the game, username is automatically synchronized).

i tried the following // in create() method of game class userPreferences = Gdx.app.getPreferences("userPrefs");

then, in my registration stage

enter.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { super.clicked(event, x, y); user.username = usernameField.getText(); PanBallGame.getGameInstance().userPreferences.putString("username", user.username); user.requestPath = "/addUser"; new RequestObserver(user); } });

but this doesn't save the username in preferences. Can anyone explain how to get this work ? Thank you .

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

You are missing flush command after put command.

public class GameManager { private static final String RESULT_BEST = "BEST_RESULT"; public String userID; private Preferences PREFS; public static final GameManager INSTANCE = new GameManager(); int result; //... private GameManager() { PREFS = Gdx.app.getPreferences(GameManager.class.getSimpleName()); userID = "XXXX"; } public void setBestResult(int result) { PREFS.putInteger(RESULT_BEST, result); PREFS.flush(); //THIS IS MISSING } public int getBestResult() { return PREFS.getInteger(RESULT_BEST, 0); } 

}

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.