+ // The listener should be unregistered when the app is paused.
+ override fun onPause() {
+ // Run the default commands.
+ super.onPause()
+
+ // Get a handle for the shared preferences.
+ val sharedPreferences = preferenceScreen.sharedPreferences!!
+
+ // Unregister the shared preference listener.
+ sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener)
+ }
+
+ // The listener should be re-registered when the app is resumed.
+ override fun onResume() {
+ // Run the default commands.
+ super.onResume()
+
+ // Get a new shared preference change listener.
+ sharedPreferenceChangeListener = getSharedPreferenceChangeListener()
+
+ // Get a handle for the shared preferences.
+ val sharedPreferences = preferenceScreen.sharedPreferences!!
+
+ // Re-register the shared preference listener.
+ sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener)
+
+ // Update the realtime monitoring preference summary.
+ updateRealtimeMonitoringSummary()
+
+ // Restore the scroll position if the fragment has been restarted.
+ if (fragmentRestarted) {
+ // Reset the fragment restarted flag.
+ fragmentRestarted = false
+
+ // Set the scroll position.
+ listView.smoothScrollBy(0, scrollY)
+ }
+ }
+
+ override fun onSaveInstanceState(savedInstanceState: Bundle) {
+ // Run the default commands.
+ super.onSaveInstanceState(savedInstanceState)
+
+ // Save the scroll position.
+ savedInstanceState.putInt(SCROLL_Y, listView.computeVerticalScrollOffset())
+ }
+