Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's actually pretty simple, you use SharedPreferences to store key-value pairs. You can either call </p> <pre><code>SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this); </code></pre> <p>From the GameScreen and then define a constant: </p> <pre><code>public static final String KEY_SCORE = "score"; </code></pre> <p>To use as the key for the saving.</p> <p>In order to actually save, you need an Editor: </p> <pre><code>SharedPreferences.Editor mEditor = mPrefs.edit(); //save data now, mPlayerScore is the score you keep track of //if it's another type call putString(), etc mEditor.putInt(KEY_SCORE, mPlayerScore); //if that is the only thing you want for noe //close and commit mEditor.commit(); </code></pre> <p>And in order to retrieve the saved score, during your onCreate() you can do:</p> <pre><code>public void getUserProgress() { SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this); //no need for an editor when retrieving mPlayerScore = mPrefs.getInt(KEY_SCORE, 0); //second value passed was the default score //if no score was found } </code></pre> <p>In order to check for new character s being unlocked, you can call the following code after every game:</p> <pre><code>private void checkForUserUnlocks() { if (mPlayerScore &gt;= MyUnlockableCharacter.SCORE_NEEDED_TO_UNLOCK) MyUnlockableCharacter.isUnlocked = true; //and same for other unlockabld characters } </code></pre> <p>There are other ways to access SharedPreferences, let me know if you need more info.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload