I have two activity A & B, A activity have list of videos. After click the video it goes to B(Player) activity to play video.
Issue faced
A(Video List) --> B(Player Activity)
When i click the back button B activity goes to PIP mode. Now A is visible & B activity in PIP mode(Video Playing). Again i click the back button it closed the A activity, but B still in PIP Mode. Now B activity leave PIP mode to Full activity.
Now again click the back button, i want to show the A as back stack B activity to PIP mode. But B activity goes to PIP mode but Back screen as homes screen.
When i clicked the Home button while in B activity, B activity goes to PIP mode. B activity in PIP now can access the home screens. Now click the PIP mode screen to full activity.
Now again click the back button, i want to show the A as back stack B activity to PIP mode. But B activity goes to PIP mode but Back screen as homes screen.
Manifest
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"/>
<activity
android:name=".PlayerActivity"
android:allowTaskReparenting="true"
android:autoRemoveFromRecents="true"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|layoutDirection"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:resizeableActivity="true"
android:screenOrientation="sensor"
android:supportsPictureInPicture="true" />
Picuture-in-Picture code
private void pictureInPictureMode() {
if (supportsPiPMode() && getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
Rational aspectRatio = new Rational(playerView.getWidth(), playerView.getHeight());
pictureInPictureParamsBuilder.setAspectRatio(aspectRatio).build();
if (canEnterPiPMode()) enterPictureInPictureMode(pictureInPictureParamsBuilder.build());
}
}
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
inPIP = isInPictureInPictureMode;
if (isInPictureInPictureMode) {
landscapeViews();
bottomAdv.setVisibility(View.GONE);
} else {
portraitViews();
}
}
@Override
protected void onUserLeaveHint() {
pictureInPictureMode();
}
private boolean canEnterPiPMode() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
return (AppOpsManager.MODE_ALLOWED == appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_PICTURE_IN_PICTURE, Process.myUid(), getPackageName()));
}
return false;
}
public boolean supportsPiPMode() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
}
In B activity whenever click the back button need A activity as back stack B to PIP mode. Guide me to solve this issue.