0
\$\begingroup\$

Can I get a value from LibGDX preferences like this:

Preferences preferences = Gdx.app.getPreferences("someName");
int value = preferences.getInteger("intValue");

And then in the same project, in a different activity, do this:

SharedPreferences preferences = getSharedPreferences("someName",Context.MODE_PRIVATE);
int value = preferences.getInt("intValue",0);

So assuming there is a value already stored, would both methods retrieve the same value?

\$\endgroup\$
0
\$\begingroup\$

Yes, you are right in assuming that both codesnippets do the same thing. Checking the implementation for the Android backend, they show that the same Android methods are being called.

@Override
public Preferences getPreferences (String name) {
    return new AndroidPreferences(getSharedPreferences(name, Context.MODE_PRIVATE));
}

Source

and

@Override
public int getInteger (String key) {
    return sharedPrefs.getInt(key, 0);
}

Source

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.