我目前正在开发一个具有2个独立活动的应用程序。 ActivityA利用PictureInPicture来显示地图,并位于ActivityB的顶部。 ActivityB在onClickListener内的ActivityA的onCreate中启动
public void onClick(View view){
Rational aspectRatio = new Rational(
OverlayActivity.this.findViewById(android.R.id.content).getRight(),
OverlayActivity.this.findViewById(android.R.id.content).getBottom());
PictureInPictureParams params = mPictureInPictureParamsBuilder
.setAspectRatio(aspectRatio)
.build();
OverlayActivity.this.enterPictureInPictureMode(params);
Intent i = new Intent(ActivityA.this, ActivityB.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
当PictureInPictureMode处于非活动状态时,我想结束ActivityB,只要在ActivityA上恢复PictureInPictureMode,它就会重新启动
onPictureInPictureModeChanged(){
if(!isInPictureInPictureMode){
//TODO: finish ActivityB
}
}
是否有这样做的机会而又不会过多地破坏活动周期?还是我没有正确启动ActivityB还是标志引起了任何问题?