我有一个在androidManifest.xml中没有历史的LiveChat活动.Livechat活动打开文件 Select 器 Select 图像或视频.

问题是,当文件 Select 器打开它时,因为活动中没有设置历史记录,所以它完成了活动.

我必须保持活动没有历史标志,因为LiveChat活动是PIP活动,当它完成时,打开两个App实例.我希望活动不应该在文件 Select 器打开时完成.

打开文件 Select 器时,我try 下面的代码片段

getIntent().removeFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

但它不起作用.有没有可能这样做.谢谢

推荐答案

如果某人面临相同的问题,他/她可以使用下面的代码片段关闭多个PIP实例,而无需使用FLAG_ACTIVITY_NO_HISTORY.

@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
    super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);

    if (getLifecycle().getCurrentState() == Lifecycle.State.CREATED) {
        finishAndRemoveTask();
        //when user click on Close button of PIP this will trigger, do what you want here
    }
    else if (getLifecycle().getCurrentState() == Lifecycle.State.STARTED){
        //when PIP maximize this will trigger
    }
}

Android相关问答推荐

如何将Hilt添加到Android Studio中的Kotlin项目中?

如何使禁用状态下的material 3按钮与启用状态下的 colored颜色 相同?

编写Landscape BoxWithRequests具有错误的高度.(aspectRatio matchHeight约束第一次未按预期工作)

如何清除导航抽屉中以前 Select 的项目(Jetpack Compose)

Jetpack Compose和Android Studio中的普通设计工具有什么不同?

DocumentFile.canWrite()、DocumentFile.Existes()-使用本地内置手机存储(而不是云)时性能较差(占用太多CPU时间)

Jetpack编写错误(java.lang.NoSuchMethodError:无接口方法startRestartGroup)

如何在初始合成期间在可组合函数中调用/获取远程API中的数据[防止无限重组]

在Delphi中使用OpenCV for Android在使用JLIST时抛出错误

Jetpack Compose 使用 SavedStateHandle 发送返回结果不适用于 ViewModel 中注入的 SavedStateHandle

在java android studio项目上安装mapbox

kotlin中&&和and的区别

Android 构建失败:找不到 flexbox2.0.1.aar

请求访问小部件中的位置权限

在Android RoomDB中使用Kotlin Flow和删除数据时如何解决错误?

Jetpack compose :使用 rememberSaveable 时未应用待处理的合成

AttributionSource 需要 android.permission.BLUETOOTH_SCAN 权限的问题

如何在jetpack compose中通过lamda返回columnScope/RowScope

firebase-messaging和firebase-inappmessaging-display之间有什么区别?

我的自定义视图没有显示我应该如何修复它?