Anusha Anusha - 1 year ago 105
Android Question

Check if app is opened for the first time in LIBGDX

I am trying to check if the app is opened for first time in LIBGDX. I want this logic to be implemented in level selection screen. I want the sprite to get different for the first time. I have implemented the below code,

private static Preferences prefs;
public MenuScreen(MyGame game) {
prefs ="firsttimeopen");
if (prefs.getBoolean("lock",true) ) {
prefs.putBoolean("lock", false);"firsttimeopening" + a, "firsttimeopening" + a);
} else {"secondtimeopening" + a, "secondtimeopening" + a);

Here both the condition becomes true when i open the app.I don't know where did I go wrong. I even referred this question stackoverflow and even this question stackoverflowbut nothing helped. Help me. Thanks in advance.

Answer Source

From the wiki:

Your changes to a preferences instance will only get persisted if you explicitly call the flush() method.

Add the line in your code:

prefs.putBoolean("lock", false);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download