简体   繁体   中英

How to allow Multi-Window feature Activity wise in Android N?

How to enable Mutli window option in android app Activity wise.?

I tried with AndroidManifest activity attribute android:resizeableActivity in two separate activities.

From Android-N Documentation what I found for above option

android:resizeableActivity=["true" | "false"]

If this attribute is set to true, the activity can be launched in split-screen and freeform modes. If the attribute is set to false, the activity does not support multi-window mode. If this value is false, and the user attempts to launch the activity in multi-window mode, the activity takes over the full screen. If your app targets Android N, but you do not specify a value for this attribute, the attribute's value defaults to true.

What I tried :

Added Two Activities One Activity is with android:resizeableActivity="false" and second Activity is with android:resizeableActivity="true" (in AndroidManifest.xml ).

<activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:resizeableActivity="true"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MWActivity"
            android:resizeableActivity="false"
            android:theme="@style/AppTheme.NoActionBar" />

For both Activities app is able to enable Mutli-window & able to Resize also.

Expected behavior as per documentation :

only MainActivity should allow to Mutli-Window & MWActivity should not be allow to resize also as i have given android:resizeableActivity="false" to MWActivity

UPDATE : As of now (In Current Version of "N") it can be consider as a Defect

This is defect in the current version of "N". From code.google check this link for more detail .

Will keep updating answer & question if anything I got.

You can do it programmatically by starting you activity as a new task only if you are in multi-window mode.

final Intent intent = new Intent(this, MWActivity.class);
if (isInMultiWindowMode())
{
   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
startActivity(intent);

This is as expected and as mentioned in Android documentation. That is a root activity's attribute settings apply to all activities within its task stack. For example, if the root activity has android:resizeableActivity set to true, then all activities in the task stack are resizeable.

In your case you have android:resizeableActivity set to true for root activity so all activity created in same task will support multi-window.

Same is documented in https://developer.android.com/preview/features/multi-window.html#configuring

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM