Hello I am using this AppCompatDelegate to change between day/night themes I have 2 activities A& B this code called from activity B it should recreating activity B & A with the chosen style here is my code
applyNight.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!isNight) { SharedPrefrencesMethods.savePreferences(this, getString(R.string.night_key), true); AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } else { SharedPrefrencesMethods.savePreferences(this, getString(R.string.night_key), false); AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } } });
I tested it on android 7 & 6 it's working fine i.e when changing mode in activity B and press back activity A recreating with the new theme. When trying it on android 9 it's changing the activity B only and not affecting it's parent activity A.