辅助显示器上的Android-O启动

时间:2017-03-23 09:05:20

标签: android api user-interface display android-8.0-oreo

当我尝试启动活动意图时,Android-O中的新ActivityOptions setLaunchDisplayId(int launchDisplayId)函数似乎总是崩溃我的应用程序。

当我从自己的应用中启动活动以及尝试启动其他应用时,包括Chrome Canary。

有没有人知道这是新API的一般问题还是我遗漏了一些东西:

我的代码的一小部分如下:

options.setLaunchDisplayId(1); startActivity(intent, options);

我正在使用'模拟第二个屏幕'进行测试(如果重要的话,@ 1080p)。

更新 我尝试过ADB命令adb shell start com.chrome.canary --display 1, 我收到了消息:

  

开始:必须是root

3 个答案:

答案 0 :(得分:4)

我已经使用下面的代码通过新API连接到第二个屏幕,但截至目前还没有办法与它进行交互。

for

答案 1 :(得分:0)

这是对我有用的简化答案,它是基于@Smiler建立的。我通过在Button中单击MainActivity对此进行了测试。感谢您的帮助!

    ((Button) findViewById(R.id.launchTopScreen)).setOnClickListener(v -> {
        Intent intent = getPackageManager().getLaunchIntentForPackage("com.example.new.app");
        intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
        ActivityOptions options = ActivityOptions.makeBasic().setLaunchDisplayId(1);
        startActivity(intent, options.toBundle());
    });

Intent.FLAG_ACTIVITY_NEW_TASK非常重要,以使新应用程序在不同的显示器上启动。否则,它将在同一任务堆栈中的同一显示器上启动。

该“新应用”还需要在清单中包含android:resizeableActivity="true"True是默认设置,但我指定了明确的设置,以保护将来的框架更改。

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:resizeableActivity="true"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

答案 2 :(得分:0)

每次添加新的模拟屏幕时,显示ID都会更改。重新启动时,它将重置为1。检查这是否是问题。您指定的adb命令似乎不起作用,如您所说。