title: Refresh the backstack Activities after Night Mode has changed
body: <p>I have seen a lot of questions and answers about recreating the current activity after changing the application's Night Mode, but I have seen nothing on how to refresh the back stack Activities.</p>
  
  <p>Say I have the backstack <strong>A > B > C</strong>. Activity C allows to change the night mode by calling <code>AppCompatDelegate.setDefaultNightMode()</code>. After this call, the current Activity (C), can refresh its theme with <code>delegate.applyDayNight()</code> or <code>recreate()</code>.</p>
  
  <p>However, when the user navigates back to B or A, the activities are still using the "old" mode, either day or night. </p>
  
  <p>I tried to add something like that to the Activities:</p>
  
  <pre><code>override fun onResume() {
    super.onResume()
    delegate.applyDayNight()
  }
  </code></pre>
  
  <p>But it does not seem to work. </p>
  
  <p>I did multiple attempts to fix this:</p>
  
  <p>One idea would be to recreate the backstack completely like suggested <a href="https://stackoverflow.com/a/28799124/183665">here</a> or <a href="https://stackoverflow.com/q/31197843/183665">here</a>, but since the backstack is not static, it's not doable for me.</p>
  
  <p>Another idea would be to have a class that handles the night mode change and provides a LiveData. Each Activity would listen to the LiveData for a mode change and call <code>recreate()</code>. However, we are stuck in an infinite loop because the Activity would recreate directly after starting to listen to the LiveData.</p>
  
  <p>I find it hard to believe that I am the first one trying to refresh the Activities from the backstack after changing the night mode. What did I miss?</p>
  
  <p>Thanks!</p>