我正在创建一个媒体播放器应用程序,我想支持画中画。我的问题是,每当我进入PIP时,播放器活动便会与上一个活动分开。
这是我的活动声明:
[INFO] [ERROR ] CWWJP0015E: An error occurred in the org.hibernate.jpa.HibernatePersistenceProvider persistence provider when it attempted to create the container entity manager factory for the jpaunit
这是我用来输入画中画的代码:
<activity
android:name=".ui.player.PlayerActivity"
android:allowTaskReparenting="true"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
android:exported="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/player"
android:launchMode="singleTask"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsPictureInPicture="true">
答案 0 :(得分:0)
避免这种情况的最好方法是使用一项活动并将东西作为碎片
答案 1 :(得分:0)
在将 PIP 扩展回应用程序后,我在运行多个任务时遇到问题。我们使用多个活动,因为我们希望 PIP 在应用程序中运行。因此,当用户触发扩展/恢复 pip 时,我调用此方法:
public static boolean removeLauncherTask(Context appContext) {
ActivityManager activityManager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
// iterate app tasks available and navigate to launcher task (browse task)
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)) {
PictureInPictureActivity.mBackstackLost = true; // to keep track
task.setExcludeFromRecents(true);
return true;
}
}
return false;
}
在恢复 pip 后你仍然需要处理你的 backstack,但许多帖子已经解决了这个问题。提示如果您丢失了 backstack,则需要在从 pip 活动导航后调用此方法
public static boolean navToLauncherTask(Context appContext) {
ActivityManager activityManager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
// iterate app tasks available and navigate to launcher task (browse task)
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 true;
}
}
return false;
}
''''
Which looks very similar as the removing of the main task.