Search code examples
androidandroid-studioandroid-night-mode

App crashes after switching night mode and mediaplayer stops


I have created an audio player app using Media Player, which streams a url from a JSON file. Everything works fine when switching UI mode (night mode to day mode & day mode to night mode), but it stops playing audio if I set datasource again then it crashes.

After Googling I found a solution, I did some changes in the manifest.xml file:

 <activity
        android:name=".MainActivity"
        android:configChanges="uiMode"
        android:launchMode="singleTask">

Now the media player is working properly, but I have to face another issue:

enter image description here

enter image description here

Some text color is matched with the background color and this issue comes up when I switch system UI mode to night mode after opening the app. If I open the app and scroll to the last item and then switch mode to night mode then this issue does not come up.

I am not sharing any code snippet here, as I have no idea which code I should share.


Solution

  • I think this could solve your problem...

    @Override
        protected void onNightModeChanged(int mode) {
            super.onNightModeChanged(mode);
        }