Programmatically open app in split screen

时光总嘲笑我的痴心妄想 提交于 2021-02-18 19:19:21

问题


How do I open another app in a split screen in the android N (SDK 24)?

In the documentation I found this:


Launch New Activities in Multi-Window Mode

When you launch a new activity, you can hint to the system that the new activity should be displayed adjacent to the current one, if possible. To do this, use the flag Intent.FLAG_ACTIVITY_LAUNCH_TO_ADJACENT. Passing this flag requests the following behaviour:

If the device is in split-screen mode, the system attempts to create the new activity next to the activity that launched it, so the two activities share the screen. The system is not guaranteed to be able to do this, but it makes the activities adjacent if possible. If the device is not in split-screen mode, this flag has no effect. If a device is in freeform mode and you are launching a new activity, you can specify the new activity's dimensions and screen location by calling ActivityOptions.setLaunchBounds(). This method has no effect if the device is not in multi-window mode.


so when I tried this out, the Intent.FLAG_ACTIVITY_LAUNCH_TO_ADJACENT flag does not exist. I installed

  • Android 6.x (N) SDK 24 revision 1
  • Android N Preview SDK N revision 3
  • Android 6.0 (Marshmallow) SDK 23 revision 3

this is my gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "PACKAGENAME"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 2
        versionName "2.4.1"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.android.support:design:24.0.0'
    compile 'org.jsoup:jsoup:1.8.3'
    compile 'com.android.support:support-v4:24.0.0'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
}

回答1:


First of all app should be targeted to SDK 24+ version. If it targeted to lower than 24 SDK then split screen mode would not work. Then carefully read here and here

If the device is in split-screen mode, the system attempts to create the new activity next to the activity that launched it, so the two activities share the screen. The system is not guaranteed to be able to do this, but it makes the activities adjacent if possible.

This flag is only used in split-screen multi-window mode. The new activity will be displayed adjacent to the one launching it. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK. Also, setting FLAG_ACTIVITY_MULTIPLE_TASK is required if you want a new instance of an existing activity to be created.

It means that you can't start split screen mode programmatically. You can just try to launch activity in another part of screen if you are already in split screen mode.



来源:https://stackoverflow.com/questions/37907094/programmatically-open-app-in-split-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!