title: SharedPreferences String Set data lost after app kill (android emulator)
body: <p>I am running this on an emulator: 5554:Nexus_5_API_22_x86.</p>
  
  <p>I am trying to learn SharedPreferences and have written a simple test program.</p>
  
  <p>It contains two buttons: one adds a String + random # to a set which will be stored in SharedPreferences, and the other prints the contents of that set.</p>
  
  <p>Whenever I press the square button on the bottom right hand of the screen and press 'x' to close the app window, then relaunch the app, the contents of the set are reset - in other words, printing the set yields nothing. </p>
  
  <p>However, if I exit the app using only the back button, the contents remain - in other words, printing the set yields whatever was in it before.</p>
  
  <p>Java:</p>
  
  <pre><code>...
  
  public class MainActivity extends AppCompatActivity
  {
      final int PREF_MODE_PRIVATE = 0;
      TextView output;
      Set&lt;String&gt; testSet;
      Random randomGenerator = new Random();
      SharedPreferences data;
      SharedPreferences.Editor dataEditor;
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          output = (TextView) findViewById(R.id.textView); //getting the output textfield
          data = getPreferences(PREF_MODE_PRIVATE);
  
          //If first-time setup has not been completed, execute the following block
          //I don't want the String Set to be reset to empty every time the app is launched
          if(data.getBoolean("initialized", false) == false)
          {
              //Adding the empty set to storage
              testSet = new HashSet&lt;String&gt;();
  
              dataEditor = data.edit();
              dataEditor.putStringSet("testSet", testSet); //Add the empty Set to storage
              dataEditor.putBoolean("initialized", true); //Set initialized flag to true
              dataEditor.apply();
          }
      }
  
      public void printTestSet(View view)
      {
          output.setText(""); //Clears the text field
          Set&lt;String&gt; toBePrinted = data.getStringSet("testSet", null); //Gets the String Set
  
          //Prints content of the String Set
          if(toBePrinted != null)
          {
              for(String word : toBePrinted)
              {
                  output.append(word + '\n');
              }
          }
      }
  
      public void addToTestSet(View view)
      {
          //Generate a string followed by a random number and add it to the String Set
          int randomInt = randomGenerator.nextInt(1000);
          data.getStringSet("testSet", null).add("NEW STRING #" + randomInt);
      }
  }
  </code></pre>
  
  <p>The button that prints the String Set calls <code>printTestSet</code> and the one that adds a String to the Set calls <code>addToTestSet</code>. </p>
  
  <p>Upon creation, the app uses a simple boolean to check if it has been initialized the for the first time. If not, it adds an empty String Set to storage and sets the boolean to true. If the boolean is already true (meaning it has already added the empty string set), that step is skipped.</p>