title: userPreferences acting weird, not saving or retrieving all key-values, what am I doing wrong?
body: <p>I have an ultra simple calculator which outputs some numbers to 4 separate labels. It is essential to the users experience that the labels hold data over app kills, back button, etc.</p>
  <p>Currently I have userPreferences setup as per instructions. It seems super simple but when returning to the activity screen in different situations all labels contain the same number as only one of the labels. Example:</p>
  <p>Actual:</p>
  <pre><code>label 1: 90
  label 2: 90
  label 3: 90
  label 4: 90
  </code></pre>
  <p>Expected:</p>
  <pre><code>label 1: 90
  label 2: 2030
  label 3: 40654
  label 4: *list of calculations from above numbers*
  </code></pre>
  <p>I have tried various combinations of retrieving the data from override fun onResume, onStart, onRestart as well as saving in onStop, onPause, onDestroy etc... Nothing worked, still same output as above.</p>
  <p>EDIT: on a positive note, user preferences is indeed saving that one single label data throughout all lifecycle situations...</p>
  <p>Here is my code as it stands now with none of the activity lifecycle attempts:</p>
  <pre><code>class Calc : AppCompatActivity() {
  
  @RequiresApi(Build.VERSION_CODES.KITKAT)
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      this.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT //Set Portrait only
      setContentView(R.layout.activity_calc)
  
      // Instantiate SharedPreferences for saving user input
      val pref: SharedPreferences = applicationContext.getSharedPreferences(&quot;MyPref&quot;, 
  MODE_PRIVATE) ?: return // Call to assign saved value
      val editor: SharedPreferences.Editor = pref.edit() // Call editor. to save to file
  
      // Retrieve saved data if it exists
      if (pref.contains(UNIT) &amp;&amp;
          pref.contains(VOLUME) &amp;&amp;
          pref.contains(HEIGHT) &amp;&amp;
          pref.contains(CALCULATION)) {
          unit.text = pref.getString(UNIT, &quot;&quot;)
          volume.text = pref.getString(VOLUME, &quot;&quot;)
          height.text = pref.getString(HEIGHT, &quot;&quot;)
          calculation.text = pref.getString(CALCULATION, &quot;&quot;)
      }
  
      val popup = Utilities
      // Declare calculate button and call function to crunch numbers and output them
      calculateButton.setOnClickListener {
  
          hideKeyboard() // Hide keyboard on button press
          editor.clear() // Clears saved data
  
  //
  // Bunch of calculator code that assigns numbers to 4 output labels...
  //
  
              // Save data to sharedPreferences
              editor.putString(UNIT, outputUnit.text.toString())
              editor.putString(VOLUME, outputVolume.text.toString())
              editor.putString(HEIGHT, outputHeight.text.toString())
              editor.putString(CALCULATION, outputCalculation.text.toString())
              editor.apply() // Finalizes save asynchronously
          }
      }
  }
  </code></pre>
  <p>Instanced in a .Kt file:</p>
  <pre><code>const val UNIT = &quot;&quot;
  const val VOLUME = &quot;&quot;
  const val HEIGHT = &quot;&quot;
  const val CALCULATION = &quot;&quot;
  </code></pre>