diff --git a/android/titanium/src/java/org/appcelerator/titanium/TiBaseActivity.java b/android/titanium/src/java/org/appcelerator/titanium/TiBaseActivity.java index 8421b066570..341e8018c0f 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/TiBaseActivity.java +++ b/android/titanium/src/java/org/appcelerator/titanium/TiBaseActivity.java @@ -68,7 +68,6 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; -import androidx.core.app.ActivityCompat; import android.text.Spannable; import android.text.SpannableStringBuilder; @@ -133,7 +132,6 @@ void onRequestPermissionsResult( protected int msgId = -1; //Storing the activity's dialogs and their persistence private final CopyOnWriteArrayList dialogs = new CopyOnWriteArrayList<>(); - public TiWindowProxy lwWindow; public boolean isResumed = false; @@ -671,7 +669,6 @@ protected void attachBaseContext(Context newBase) protected void onCreate(Bundle savedInstanceState) { Log.d(TAG, "Activity " + this + " onCreate", Log.DEBUG_MODE); - this.inForeground = true; this.launchIntent = getIntent(); this.safeAreaMonitor = new TiActivitySafeAreaMonitor(this); @@ -1239,11 +1236,21 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) final int NIGHT_MASK = Configuration.UI_MODE_NIGHT_MASK; if ((newConfig.uiMode & NIGHT_MASK) != (this.lastUIModeFlags & NIGHT_MASK)) { this.lastNightMode = AppCompatDelegate.getDefaultNightMode(); - ActivityCompat.recreate(this); + this.updateActivity(); } this.lastUIModeFlags = newConfig.uiMode; } + private void updateActivity() + { + /** + * Set root activity to null to avoid duplication which causes the window + * to lose all it's content when the activity is recreated. + */ + getTiApp().setRootActivity(null); + this.recreate(); + } + @Override protected void onNightModeChanged(int mode) { @@ -1256,7 +1263,7 @@ public void applyNightMode() int mode = AppCompatDelegate.getDefaultNightMode(); if (this.inForeground && (mode != this.lastNightMode)) { this.lastNightMode = mode; - ActivityCompat.recreate(this); + this.updateActivity(); } }