title: OnSharedPreferenceChangeListener not called anymore
body: <p>For a very simple app to send data to an API, I decided to use the OnSharedPreferenceChangeListener to set up the UI based on the authentication status. I either show the authentication fragment or the sending fragment and switch when the <em>status</em> changes:</p>
  <p>Listener registration:</p>
  <pre><code>val sharedPreferences = this.applicationContext.getSharedPreferences(ApplicationConstants.sharedPreferencesKey, Context.MODE_PRIVATE)
  
  if (!sharedPreferences.contains(ApplicationConstants.authTokenPreferenceKey))
      sharedPreferences.edit().putString(ApplicationConstants.authTokenPreferenceKey, null).apply()
  
  // change fragment based on shared preference value (login status)
  sharedPreferences.registerOnSharedPreferenceChangeListener { sp, key -&gt;
          if (!key.equals(ApplicationConstants.authTokenPreferenceKey))
              return@registerOnSharedPreferenceChangeListener
  
          if (sp.getString(key, null) == null) {
              // goto identity fragment if no already there
              if (!this.isCurrentFragmentOfTag(IdentityFragment::class.java.name))
                  this.replaceFragment(IdentityFragment())
          } else {
              // goto tracking fragment if not already there
              if (!this.isCurrentFragmentOfTag(TrackingFragment::class.java.name))
                  this.replaceFragment(TrackingFragment())
          }
      }
  
  if (sharedPreferences.getString(ApplicationConstants.authTokenPreferenceKey, null) == null)
      this.replaceFragment(IdentityFragment())
  else
      this.replaceFragment(TrackingFragment())
  </code></pre>
  <p>Setting the <em>status</em> when authenticated:</p>
  <pre><code>CoroutineScope(Dispatchers.IO).launch {
      try {
          val response = RetrofitInstance.api.sendLoginRequest(LoginRequest(usernameEmail, password))
          if (response.isSuccessful) {
              CoroutineScope(Dispatchers.Main).launch { // was just a try if that's the reason. Dont know if necessary
                  view.context.applicationContext.getSharedPreferences(ApplicationConstants.sharedPreferencesKey, Context.MODE_PRIVATE)
                      .edit().putString(ApplicationConstants.authTokenPreferenceKey, &quot;Bearer &quot; + response.body()?.token)
                      .apply()
              }
          } else {
              Toast.makeText(view.context, &quot;Login up error&quot;, Toast.LENGTH_LONG).show()
          }
      } catch (e: Exception) {
          Toast.makeText(view.context, &quot;Login up error: &quot; + e.message, Toast.LENGTH_LONG).show()
      }
  }
  </code></pre>
  <p>deleting the <em>status</em> to log out:</p>
  <pre><code>textViewLogout.setOnClickListener {
      view.context.applicationContext.getSharedPreferences(ApplicationConstants.sharedPreferencesKey, Context.MODE_PRIVATE)
          .edit().putString(ApplicationConstants.authTokenPreferenceKey, null).apply()
  }
  </code></pre>
  <p>The value changes all the time, but the listener is not called. When I close the app and reopen the other fragment is displayed.</p>