Repository: thundernest/k-9
Issue: Changing theme crashes settings

### Actual behavior
Changing the theme in settings makes the app crash. This was not an issue when implementing #4279. Caused by #4305?

### Environment
K-9 Mail version: 5.701-SNAPSHOT

Android version: LineageOS 16.0 

Please take some time to [retrieve logs](https://github.com/k9mail/k-9/wiki/LoggingErrors) and attach them here:

```
12-04 08:37:55.650  1993  1993 D AndroidRuntime: Shutting down VM
12-04 08:37:55.652  1993  1993 E AndroidRuntime: FATAL EXCEPTION: main
12-04 08:37:55.652  1993  1993 E AndroidRuntime: Process: com.fsck.k9.debug, PID: 1993
12-04 08:37:55.652  1993  1993 E AndroidRuntime: kotlin.UninitializedPropertyAccessException: lateinit property searchPreferenceActionView has not been initialized
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at com.fsck.k9.ui.settings.general.GeneralSettingsActivity.onSaveInstanceState(GeneralSettingsActivity.kt:50)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.app.Activity.performSaveInstanceState(Activity.java:1550)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1443)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.app.ActivityThread.callActivityOnSaveInstanceState(ActivityThread.java:4848)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.app.ActivityThread.callActivityOnStop(ActivityThread.java:4195)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:4796)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4732)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:55)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:4782)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.app.ActivityThread.access$3200(ActivityThread.java:200)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1826)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:106)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:193)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6718)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
12-04 08:37:55.652  1993  1993 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
12-04 08:37:55.657 20235 28140 W ActivityManager:   Force finishing activity com.fsck.k9.debug/com.fsck.k9.ui.settings.general.GeneralSettingsActivity
12-04 08:37:55.665 20235 20336 I ActivityManager: Showing crash dialog for package com.fsck.k9.debug u0

```

Changed files:
app/ui/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsActivity.kt

diff --git a/app/ui/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsActivity.kt b/app/ui/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsActivity.kt
index e0d9f2376..087fdc974 100644
--- a/app/ui/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsActivity.kt
+++ b/app/ui/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsActivity.kt
@@ -36,8 +36,8 @@ class GeneralSettingsActivity : K9Activity(), OnPreferenceStartScreenCallback, S
                 add(R.id.generalSettingsContainer, GeneralSettingsFragment.create())
             }
         } else {
-            searchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY) ?: error("Missing instance state")
-            searchEnabled = savedInstanceState.getBoolean(KEY_SEARCH_ENABLED)
+            searchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY, "")
+            searchEnabled = savedInstanceState.getBoolean(KEY_SEARCH_ENABLED, false)
         }
     }
 
@@ -47,9 +47,11 @@ class GeneralSettingsActivity : K9Activity(), OnPreferenceStartScreenCallback, S
     }
 
     override fun onSaveInstanceState(outState: Bundle) {
-        outState.putString(KEY_SEARCH_QUERY, searchPreferenceActionView.query.toString())
-        outState.putBoolean(KEY_SEARCH_ENABLED, !searchPreferenceActionView.isIconified)
-        searchPreferenceActionView.onBackPressed()
+        if (::searchPreferenceActionView.isInitialized) {
+            outState.putString(KEY_SEARCH_QUERY, searchPreferenceActionView.query.toString())
+            outState.putBoolean(KEY_SEARCH_ENABLED, !searchPreferenceActionView.isIconified)
+            searchPreferenceActionView.onBackPressed()
+        }
         super.onSaveInstanceState(outState)
     }