Multi-Window and Your App
Android 7.0 and Chrome OS
Forms of Multi-Window
- Split-screen
- Picture-in-picture: mostly for Android TV
- Freeform
- Chrome OS: freeform kinda sorta but not
Getting Your App in Multi-Window
- Generally, do nothing unusual
- Your app winds up in windows... whether you like it or not
- Older
targetSdkVersion
may give a warning Toast
to the user
Getting Your App Out of Multi-Window
The Theory
- Use
android:resizeableActivity="false"
on <activity>
- Older
targetSdkVersion
and android:screenOrientation
Getting Your App Out of Multi-Window
The Reality
- Root activity of the task determines the window behavior
-
Exported activities attempting to break out of multi-window need to ensure they run in a task other than default
- Some third-party apps might specifically launch you in their own task, to force you back into a window
- Changes in task behavior may impact other things (BACK behavior, overview screen entries)
About the Sizing
- User can change the size of the window (e.g., drag split bar in split-screen)
- Your window might be as small as 220dp in either direction
- Bonus: if you can handle this, you can handle
small
-rated devices
- Can specify a minimum size, but then your UI is cropped
Lifecycle Methods
Pause for a Moment and Think About onPause()
- Paused = visible but not receiving user input
- Stopped = no longer visible
- Outside of multi-window, being only paused is unusual
- With multi-window, being only paused is very common
- Are you doing the right thing when you are paused?
Configuration Changes
-
By default, activity may be destroyed and recreated due to multi-window
- User enters multi-window with your activity visible
- User resizes your window (if big enough change)
- User exits multi-window with your activity focused
android:configChanges
now "out of the doghouse"
- Note: your orientation flips when entering/exiting split-screen mode
Not All HOMEs Are Created Equal
- We expect to get called with
onStop()
when the user presses HOME
- Still true in single-window mode, plus split-screen mode if you are in bottom/right pane
-
Not true if you are in top/left pane of split-screen mode
- Supposed to be a transient state
- May cause problems if you hold wakelocks, continue playing media, etc.
Launching Another Window
- Add
FLAG_ACTIVITY_LAUNCH_ADJACENT
, along with appropriate task flags, to Intent
- Ignored if device is not in multi-window mode
- "This flag is only used in split-screen multi-window mode" (???)
- If activity exported, third-party apps can add this flag, force you into multi-instance state
Detecting Multi-Window
What Probably Works: onMultiWindowModeChanged()
- Override on your
Activity
or Fragment
- Do something useful (e.g., enable/disable "launch adjacent" action bar item)
Detecting Multi-Window
Then, There Is isInMultiWindowMode()
- User exits multi-window mode; your activity may be destroyed and recreated
- In
onCreate()
, isInMultiWindowMode()
returns true
(???) for a while (?!?) after which it returns false
, even if you never left the main application thread (?!?!?)
- IOW, a race condition ... but one that is "working as intended"
Draggin' and Droppin'
startDrag()
, OnDragListener
, and kin
- Ill-used, but around since API Level 11
- Works across activities, if both are visible
-
Cross-app behavior
- Opt-in to initiate a drag event that can be dropped in another app's window
- Cannot avoid cross-app drop events
Hey, What About Freeform?
Manufacturers of larger devices can choose to enable freeform mode, in which the user can freely resize each activity. If the manufacturer enables this feature, the device offers freeform mode in addition to split-screen mode.
Hey, What About Freeform?
- Docs say that you should test on freeform
- Officially, it does not exist
- Unofficially,
adb shell settings put global enable_freeform_support 1
and reboot
Android on Chrome OS
- Available for Acer Chromebook R11/C738T, ASUS Chromebook Flip, and 2015 Google Chromebook Pixel
- Rollout to everyone else... someday
Chrome OS and Your App
-
By default, most apps will ship to Chrome OS devices that support touchscreens
- Unclear what percentage of Chrome OS market has touchscreens
- Other app features might still block availability on these Chromebooks
- By default, most apps will not ship to Chrome OS devices that lack touchscreens
What's Different on Chrome OS
Windows
- Landscape
- Portrait
- Full-screen
- Future: N freeform?
What's Different on Chrome OS
Stuff Chrome OS Doesn't Like
android.software.input_methods
: for implementing your own IME
android.software.app_widget
: for apps whose primary purpose is to publish an app widget
android.software.live_wallpaper
: for apps whose primary purpose is to publish some live wallpaper
android.software.home_screen
: for home screen replacement apps
What's Different on Chrome OS
Not Always a Touchscreen
- Many Chromebooks, all Chromeboxes/Chromebits lack touchscreens
- Need to say that touchscreen is not required in the manifest to be distributed to such devices
- To do that, need to adequately test your app with keyboard/mouse combination
- Do not assume a trackpad!
What's Different on Chrome OS
Other Fiddly Bits
- Notifications: basics work, but get converted into Chrome OS-style notifications
Theme.Translucent
: still gets a window
- External displays: owned by Chrome OS, no
Presentation
What's Different on Chrome OS
Oh, and Then There are Bugs
- Hardcoded support to go to Play Store for certain requests (e.g.,
ACTION_VIEW
of PDF) if no app is installed
- URL-handling
<intent-filter>
elements ignored by browser
ACTION_IMAGE_CAPTURE
causes Chrome OS reboot
- Changing font scale in Settings does not work
- And so on
Testing on Chrome OS
Enabling Side-Loading
- Move your device into "developer mode" (details vary by device)
- Prepare to press Ctrl-D on every reboot (or wait 30 seconds)
- Enable "unknown sources" in Android's Settings app
Testing on Chrome OS
adb
- Seriously nasty set of instructions, affecting Chrome OS device and your development machine
- End result: use
adb connect [IP]:22
to connect to Chrome OS device, run apps from Android Studio
What You Should Worry About Now
Android 7.0 Multi-Window
- Does your app fit within a small window?
- Does your opt-out strategy really work?
- Are you handling
onPause()
properly?
- Do you need to optimize configuration changes?
- Is your drag-and-drop safe?
What You Should Worry About Now
Android on Chrome OS
- Grab a developer device, do some light testing
- Nothing much more, unless Chrome OS support is strategic, since no idea when this will widely ship
- Consider hacky opt-out (e.g., require
android.software.app_widget
) if seeing problems or wish to avoid lots of testing work