diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index e3abd32b1..e72d4609e 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -460,7 +460,9 @@ public class MainActivity extends AppCompatActivity { if (!isChangingConfigurations()) { StateSaver.clearStateFiles(); } - unregisterReceiver(broadcastReceiver); + if (broadcastReceiver != null) { + unregisterReceiver(broadcastReceiver); + } } @Override @@ -811,8 +813,20 @@ public class MainActivity extends AppCompatActivity { final Fragment fragmentPlayer = getSupportFragmentManager() .findFragmentById(R.id.fragment_player_holder); if (fragmentPlayer == null) { + /* + * We still don't have a fragment attached to the activity. + * It can happen when a user started popup or background players + * without opening a stream inside the fragment. + * Adding it in a collapsed state (only mini player will be visible) + * */ NavigationHelper.showMiniPlayer(getSupportFragmentManager()); } + /* + * At this point the player is added 100%, we can unregister. + * Other actions are useless since the fragment will not be removed after that + * */ + unregisterReceiver(broadcastReceiver); + broadcastReceiver = null; } } }; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 39ee38220..cf993ccbb 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -304,7 +304,7 @@ public class VideoDetailFragment return instance; } - public static VideoDetailFragment getInstanceCollapsed() { + public static VideoDetailFragment getInstanceInCollapsedState() { final VideoDetailFragment instance = new VideoDetailFragment(); instance.bottomSheetState = BottomSheetBehavior.STATE_COLLAPSED; return instance; diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index ac5e9c449..eef70c1e5 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -392,7 +392,7 @@ public final class NavigationHelper { } public static void showMiniPlayer(final FragmentManager fragmentManager) { - final VideoDetailFragment instance = VideoDetailFragment.getInstanceCollapsed(); + final VideoDetailFragment instance = VideoDetailFragment.getInstanceInCollapsedState(); defaultTransaction(fragmentManager) .replace(R.id.fragment_player_holder, instance) .runOnCommit(() -> sendPlayerStartedEvent(instance.requireActivity()))