2

My MainActivity supports Android N's new multi-window mode. However, I would like my AwesomeActivity to NOT support multi-window.

I have tried the following:

AndroidManifest.xml

<activity
    android:name=".activities.MainActivity"
    android:label="@string/app_name"
    android:windowSoftInputMode="stateHidden"/>
<activity android:name=".activities.AwesomeActivity"
    android:resizeableActivity="false" />

MainActivity.java

Intent intent = new Intent(this, AwesomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
//removing CLEAR_TOP and SINGLE_TOP has no effect either
//Intent.FLAG_ACTIVITY_CLEAR_TASK in conjunction with Intent.FLAG_ACTIVITY_NEW_TASK does not have an effect either

I thought that by adding the Intent.FLAG_ACTIVITY_NEW_TASK (with or without Intent.FLAG_ACTIVITY_CLEAR_TASK), this would mean that AwesomeActivity would be the root activity in its own task stack and therefore, I should not be able to get to multi-window mode at AwesomeActivity.

However, this does not work, I can still switch to multi-window mode from AwesomeActivity, which is not the desired behavior.

Although the combination of Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK seems to work to launch AwesomeActivity this doesn't work in the sense that if you put the app in the background while in AwesomeActivity, then bring the AwesomeActivity back to the foreground, you will be unable to go back to MainActivity as it was wiped from the task stack. I believe in most cases, the user would want to be able to return to MainActivity so this solution is not sufficient.

VIN
  • 6,385
  • 7
  • 38
  • 77
  • What is your `targetSdkVersion`? Does anything change if you remove `CLEAR_TOP` and `SINGLE_TOP` (which, AFAIK, you do not need here)? – CommonsWare Sep 02 '16 at 16:42
  • I removed `CLEAR_TOP` and `FLAG_ACTIVITY_SINGLE` and it still does not work. – VIN Sep 02 '16 at 16:42
  • @CommonsWare TargetSdkVersion is 24 – VIN Sep 02 '16 at 17:09
  • Try entering multi-window mode first, with `MainActivity` up. Then, start `AwesomeActivity`. Does the device fall out of multi-window mode? – CommonsWare Sep 02 '16 at 17:14
  • @CommonsWare No, the device doesn't fall out of multi-window mode when I get to AwesomeActivity :( – VIN Sep 02 '16 at 17:20
  • How strange. I haven't played with this within a single app. I have used `android:resizeableActivity="false"` for an activity launched by another app, and there it correctly bounces the user out of multi-window mode. I'll have to run some experiments... – CommonsWare Sep 02 '16 at 17:25
  • @Klone: Did you solved issue? I am have same issue!:( – AndiGeeky Mar 09 '17 at 12:09
  • @AndiGeeky unfortunately no, I was not able to resolve this issue. – VIN Mar 09 '17 at 14:40

2 Answers2

0

FLAG_ACTIVITY_NEW_TASK appears to be insufficient. Using both FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_MULTIPLE_TASK works:

      startActivity(new Intent(MainActivity.this, ActivityTwo.class)
        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_MULTIPLE_TASK));
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • If you do this, try putting the app in the background while in ActivityTwo, then bringing it back to the foreground, then press the soft back button. The app will close since MainActivity was wiped from the task stack. This is not the desired behavior. – VIN Sep 02 '16 at 18:17
  • @Kaleb: Well, BACK only takes you back within a task. You can make the other task visible by using `android:taskAffinity` (in which case, you do not need `FLAG_ACTIVITY_MULTIPLE_TASK`), but BACK within your non-resizeable task will still dump you back at the home screen by default when you destroy the task root. You would have to do some fancy shenanigans in `onBackPressed()` of `AwesomeActivity` to direct the user somewhere else. Or, make both activities non-resizeable, or make both activities resizeable. I'm not aware of other options here. – CommonsWare Sep 02 '16 at 18:27
-1

add this and try, I haven't verified android:resizeableActivity="false"

Please check this link for assistance https://developer.android.com/guide/topics/ui/multi-window.html#overview