title: Problem ending programmatically an activity right after setting SharedPreferences
body: <p>The problem I have now seems so basic that someone else must have faced it before me.</p>
  <p>Here is the code, it just saves some preferences to be used later on:</p>
  <pre><code>val editor: SharedPreferences.Editor = sharedPreferences!!.edit()
  editor.putString(&quot;activeFolder&quot;, &quot;FavoriteFolder&quot;)
  editor.commit()
  //finish()
  </code></pre>
  <p>Before that <em>sharedPreferences</em> is declared at the class level like this:</p>
  <pre><code>private var sharedPreferences: SharedPreferences? = null
  </code></pre>
  <p>An it is initialized inside <em>onCreate()</em>:</p>
  <pre><code>override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      ....
      sharedPreferences = getSharedPreferences(&quot;MyNiceApp&quot;, MODE_PRIVATE)
      ....
  }
  </code></pre>
  <p>After the code is executed I quit the activity by tapping the <em>back button</em> and all is good.</p>
  <p>Finally here is the use case causing trouble. In the situation where there is nothing else to do after saving the preferences, instead of having the user manually tapping the <em>back button</em> I want the activity to automatically terninate and for that I call finish() (commented out in the code above). When doing that the activity closes as expected, but for some unknown reason the new preferences are not taken into account.</p>
  <p>What do I need to do change to solve this issue?</p>