I've followed the Android picture-in-picture documentation. That is to say, my PiP activity is marked android:launchMode="singleTask"
, android:resizeableActivity="true"
, and android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
in the manifest.
Picture-in-picture seems to work great. However, I have noticed a case where I am experiencing undesirable behavior.
When my app receives a push, I create a PendingIntent
with an Intent
for MyActivity
(different Activity
than the PiP Activity
). However, when I tap on the notification and the Intent
is used, MyActivity
is launching inside the PiP window!
I've tried adding android:launchMode="singleTask"
to MyActivity
in the manifest. I've also tried adding that flag programmatically to the Intent
before using it with PendingIntent.getActivity()
. This does not seem to fix the issue.
Can anyone tell me how to prevent this?
Picture-in-picture (PiP) shrinks a video into a small player so you can keep watching while using other apps on your mobile device. You can move the small player around your device's home screen and position it over other apps.
The user can bring up a PIP menu that lets them toggle the PIP window to full-screen, or close the PIP window, by holding down the Home button on the remote.
To disable the Picture-in-Picture mode Find and tap Settings > Apps & notifications > Advanced > Special app access > Picture-in-picture.
First of all, as you can see in google sample codes, it does not need to make the launch mode of PIP Activity
singleTask. However, you need to move the launcher task to front which is not in PIP mode, in order to disabling PIP state.
By calling bellow snippet in the onCreate()
method of the target Activity
which is called from notifications, you can achieve this.
public static void moveLauncherTaskToFront(Context context) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
assert activityManager != null;
final List<ActivityManager.AppTask> appTasks = activityManager.getAppTasks();
for (ActivityManager.AppTask task : appTasks) {
final Intent baseIntent = task.getTaskInfo().baseIntent;
final Set<String> categories = baseIntent.getCategories();
if (categories != null && categories.contains(Intent.CATEGORY_LAUNCHER)) {
task.moveToFront();
return;
}
}
}
---------------------- Before ---------------------------------------------- After ------------------------
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With