title: BinderProxy cannot be cast to ClientTransaction exception when changing DefaultNightMode
body: <p>My app has got a single activity with a bottom navigation and multiple fragments and I'm using Navigation component.</p>
  
  <p>In my settings fragment I have a ListPreference where the user can switch between light and dark mode.</p>
  
  <pre><code>if (themePreference != null) {
              String[] entries = {getResources().getString(R.string.dark), getResources().getString(R.string.light)};
              String[] entryValues = {Integer.toString(MODE_NIGHT_YES), Integer.toString(MODE_NIGHT_NO)};
              themePreference.setEntries(entries);
              themePreference.setEntryValues(entryValues);
  
              if (themePreference.getValue() == null) {
                  themePreference.setValue(Integer.toString(MODE_NIGHT_YES));
              }
  
              themePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                  @Override
                  public boolean onPreferenceChange(Preference preference, Object newValue) {
                      final String userSelectedValue = (String) newValue;
  
                      SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit();
                      sharedPreferencesEditor.putString(THEME, userSelectedValue);
                      sharedPreferencesEditor.apply();
  
                      AppCompatDelegate.setDefaultNightMode(Integer.parseInt(userSelectedValue));
  
                      return true;
                  }
              });
          }
  </code></pre>
  
  <p>When I select a mode from the ListPreference entries, the mode gets changed but I get this error message in Logcat:</p>
  
  <pre><code>2020-04-28 16:50:42.342 17540-17540/de.xxxx.xxxx E/ActivityInjector: get life cycle exception
      java.lang.ClassCastException: android.os.BinderProxy cannot be cast to android.app.servertransaction.ClientTransaction
          at android.app.ActivityInjector.checkAccessControl(ActivityInjector.java:24)
          at android.app.Activity.onResume(Activity.java:1854)
          at androidx.fragment.app.FragmentActivity.onResume(FragmentActivity.java:455)
          at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1454)
          at android.app.Activity.performResume(Activity.java:8051)
          at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4236)
          at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4278)
          at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
          at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
          at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:57)
          at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:5298)
          at android.app.ActivityThread.access$3500(ActivityThread.java:220)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2050)
          at android.os.Handler.dispatchMessage(Handler.java:107)
          at android.os.Looper.loop(Looper.java:224)
          at android.app.ActivityThread.main(ActivityThread.java:7520)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
  </code></pre>
  
  <p>All explanations I have found for this error are about Binding and Services. I don't understand what this  has got to do with my case though. Is it because of the recreation of the activity when it changes to night/day mode?</p>
  
  <p>It happens when I try this on my Xiaomi Mi 9 but not with the emulator and for example Pixel 3 or Nexus 4. Maybe this is a Xiaomi problem?</p>
  
  <p>Any idea how to fix this? Thanks in advance.</p>
  
  <p>Edit:</p>
  
  <p>Main Activity</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements ProviderInstaller.ProviderInstallListener {
  
      private static final int ERROR_DIALOG_REQUEST_CODE = 1;
  
      private boolean retryProviderInstall;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          setTheme(R.style.AppTheme_NoActionBar);
          super.onCreate(savedInstanceState);
  
          ProviderInstaller.installIfNeededAsync(this, this);
  
          setContentView(R.layout.activity_main);
  
          Toolbar actionBarToolBar = findViewById(R.id.toolbar);
          setSupportActionBar(actionBarToolBar);
  
          BottomNavigationView navView = findViewById(R.id.nav_view);
  
          AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
                  R.id.navigation_search, R.id.navigation_bookmarks, R.id.navigation_settings, R.id.navigation_about)
                  .build();
          NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
          NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
          NavigationUI.setupWithNavController(navView, navController);
  
          onNewIntent(getIntent());
      }
  
      @Override
      public boolean onSupportNavigateUp() {
          return Navigation.findNavController(this, R.id.nav_host_fragment).navigateUp()
                  || super.onSupportNavigateUp();
      }
  
      @Override
      public void onProviderInstalled() {
          // Provider is up-to-date, app can make secure network calls.
      }
  
      @Override
      public void onProviderInstallFailed(int errorCode, Intent recoveryIntent) {
          GoogleApiAvailability availability = GoogleApiAvailability.getInstance();
          if (availability.isUserResolvableError(errorCode)) {
              // Recoverable error. Show a dialog prompting the user to
              // install/update/enable Google Play services.
              availability.showErrorDialogFragment(
                      this,
                      errorCode,
                      ERROR_DIALOG_REQUEST_CODE,
                      new DialogInterface.OnCancelListener() {
                          @Override
                          public void onCancel(DialogInterface dialog) {
                              // The user chose not to take the recovery action
                              onProviderInstallerNotAvailable();
                          }
                      });
          } else {
              // Google Play services is not available.
              onProviderInstallerNotAvailable();
          }
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode,
                                      Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          if (requestCode == ERROR_DIALOG_REQUEST_CODE) {
              retryProviderInstall = true;
          }
      }
  
      @Override
      protected void onPostResume() {
          super.onPostResume();
          if (retryProviderInstall) {
              ProviderInstaller.installIfNeededAsync(this, this);
          }
          retryProviderInstall = false;
      }
  
      private void onProviderInstallerNotAvailable() {
      }
  }
  </code></pre>