Difference between "force stop" and leaving the phone for a few hours
<p>I've had a couple of game apps on the market which attempt to save the users progress through the game with some code like this (simplified):</p>

<pre><code>public class Globals extends Application
{
    public void onCreate()
    {
         settings = getSharedPreferences("MyPrefsFile", 0);
    }

    public void get_state()
    {
        synchronized (this)
        {
            game_progress = settings.getInt("progress", 1);
        }
    }

    public void save_state()
    {
        synchronized (this)
        {
            SharedPreferences.Editor editor = settings.edit();

            editor.putInt("progress",game_progress);

            editor.commit();
        }
    }
}
</code></pre>

<p>This appears to work fine 99% of the time but every now and then I have had reports from users that their progress was lost, but nobody has ever been able to give me a sequence of actions which will enable me to repeat the bug... until now. The steps involve pressing the "home" button to exit the program and then waiting several hours. Then when they run the game again, their progress is lost. Frustratingly this sequence can not be shortened, doing a "force stop" instead of leaving the phone for several hours does not have the same effect.</p>

<p>Presumably if the phone is left for a few hours, some or all of the activities within the application may get shut down in a way which is subtly different from a force stop... but I have no idea how.</p>

<p>Any ideas?</p>

<p><strong>EDIT:</strong> I should explain how these functions are called from the various activities that comprise my games. Here's an example, but I call gs.save_state() from several other places too, just for good measure.</p>

<pre><code>    public class Main_GamePlay extends Activity
    {
        Globals gs;
        public void onCreate(Bundle savedInstanceState)
        {
             gs = ((Globals) getApplicationContext());
        }
        protected void onPause()
        {
            gs.save_state();
        }
    }
</code></pre>
