How to make a persistent counter variable in an Android app?
<p>I'm just starting out.</p>

<p>I'm trying to increment a simple counter, every time I run the project on the emulator.</p>

<p>I thought adding an <code>integer</code> type <code>item</code> in <code>strings.xml</code> would help, but that's final, and can't be modified. </p>

<p>Basically I'd just display in my app's first basic screen:</p>

<p><code>Started: N</code> where N would be the Nth time I've launched the project from Eclipse.</p>

<p>How can I make such a counter that's persistent across application launches and exits?</p>

<p>Got it:</p>

<pre><code>    SharedPreferences pref = getPreferences(MODE_PRIVATE);
    int tempN=pref.getInt("N", 0);
    tempN++;
    SharedPreferences.Editor editor = pref.edit();
    editor.putInt("N",tempN);

    editor.commit();

    msgBox.setText("Started:"+tempN);
</code></pre>

<p>One thing I still don't understand, that when I call <code>pref.getInt("N",0)</code>, is the key-value pair <code>&lt;N,0&gt;</code> automatically created?</p>
