HomeAndroidLearn how to optimize your Android app for giant screens (And what...

Learn how to optimize your Android app for giant screens (And what NOT to do!)



Posted by the Android workforce

Giant foldables, tablets, and desktop gadgets like Chromebooks – with extra lively giant display Android gadgets annually, it’s extra vital than ever for apps to make sure they supply their customers with a seamless expertise on giant screens. For instance, these gadgets supply extra display area, and customers anticipate apps to do extra with that area. We’ve seen that apps take pleasure in higher enterprise metrics on these gadgets after they do work to assist them.

These gadgets will also be used elsewhere and in numerous methods than we’d anticipate on a handset. For instance foldables can be utilized in tabletop mode, customers might sit additional away from a desktop show, and plenty of giant display gadgets could also be used with a mouse and keyboard.

These variations introduce new issues to contemplate. For instance:

  • Can a consumer attain crucial controls when utilizing your app with two palms on a pill?
  • Does all your app’s performance work with a keyboard and mouse?
  • Does your app’s digital camera preview have the fitting orientation whatever the place of the system?
image showing differentiated experiences across large sceen devices

Giant Display Design and High quality

Defining nice design and high quality on giant screens could be troublesome, as a result of completely different apps can have other ways to excel. You realize your product greatest, so it’s vital to make use of your app on giant display gadgets and mirror on what’s going to present the very best expertise. In case you don’t have entry to a big display system; attempt one of many foldable, desktop, or pill digital gadgets.

Google additionally gives assets thoughout the event course of to assist as you optimize your app. In case you’re in search of design steering, there are considerate design assets just like the giant display Materials Design steering and able to use compositions like the Canonical layouts. For inspiration, there are nice examples of quite a lot of completely different apps in the big screens gallery. In case you’re in search of a structured solution to method giant display high quality, the Giant display app high quality tips present a straight-forward guidelines and a set of checks to offer you confidence that your app is prepared for giant screens.

Dos and Don’ts of Optimizing for Giant Screens

Whether or not you have already got lovely giant display designs or not, we need to spotlight some useful suggestions and customary errors to keep away from when optimizing your app for giant screens.

Don’t: assume unique entry to assets

  • Don’t assume you’ve unique entry to {hardware} assets just like the digital camera. Giant screens generally have multiple app lively at a time, and people different apps might attempt to entry the identical assets.
  • This implies it is best to check your app facet by facet concurrently with different apps, and by no means assume a useful resource is offered at any given time.

Do: deal with {hardware} entry gracefully

  • Examine for {hardware} assets just like the digital camera earlier than attempting to make use of them. Keep in mind that {hardware} peripherals could be added and eliminated at any time by way of USB.
  • Fail gracefully when entry to a given useful resource isn’t obtainable at runtime.
attempt {

...
} catch (e: CameraAccessException) {
e.message?.let { Log.e(TAG, it) }

}
}

Do: reply appropriately to lifecycle occasions:

  • Your app should be seen throughout onPause(), particularly when a number of apps on onscreen, so you have to hold media taking part in and your UI contemporary till onStop() known as

Don’t: cease your app’s UI in onPause()

override enjoyable onPause() {

tremendous.onPause()
}

Don’t: depend on device-type booleans like “isTablet

  • Previously, a typical sample for apps to make use of was to leverage display width to create a boolean like “isTablet” to make modifications primarily based on the form of system the app is working on, however this method is fragile. The core downside with this method is that it appears for a proxy to find out what the system sort is, and people proxies are error-prone. For instance, in the event you decide a tool is a pill as a result of it has a big show when your app launches, your app can behave incorrectly when its window is resized to not take up the total display. Even when your device-type boolean responds to configuration modifications, unfolding a foldable would change your expertise in a manner that it couldn’t return to till one other configuration change happens, akin to refolding the system.

Do: work to interchange present makes use of of device-type booleans with the fitting method

Question for the details about the system that’s crucial for what you’re attempting to perform. For instance:

  • In case you’re utilizing device-type booleans to adapt your format, use WindowSizeClasses as a substitute. The library has assist for each Views and for Jetpack Compose, and it makes it clear and straightforward to adapt your UI to pre-defined breakpoints.

class MainActivity : ComponentActivity() {

setContent {
val windowSizeClass = calculateWindowSizeClass(this)
WindowSizeClassDisplay(windowSizeClass)
}

@Composable
enjoyable WindowSizeClassDisplay(windowSizeClass : WindowSizeClass) {
when (windowSizeClass.widthSizeClass)
{
WindowWidthSizeClass.Compact -> { compactLayout() }
WindowWidthSizeClass.Medium -> { mediumLayout() }
WindowWidthSizeClass.Expanded -> { expandedLayout() }
}
}

  • In case you’re utilizing isTablet for altering consumer going through strings like “your pill”, you may not want any extra data. The answer could be so simple as utilizing extra normal phrasing akin to “your Android system”.
  • In case you’re utilizing a device-type boolean to foretell the presence of a {hardware} characteristic or useful resource (e.g. – telephony, bluetooth, and so on), test for the specified capabilities immediately at runtime earlier than attempting to make use of them, and fail gracefully after they change into unavailable. This feature-based method ensures that your app can reply appropriately to peripheral gadgets that may be hooked up or eliminated. It additionally avoids instances the place a characteristic is lacking though it might be supported by the system.
val packageManager: PackageManager = context.packageManager
val hasTelephony = packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)

Do: use Jetpack CameraX when potential

  • There could be a shocking quantity of complexity in exhibiting digital camera previews – orientation, facet ratio, and extra. If you use Jetpack CameraX, the library will deal with as many of those particulars as potential for you.

Don’t: assume that your digital camera preview will align with system orientation

  • There are a number of sorts of orientation to contemplate when implementing a digital camera preview in your app – pure orientation, system orientation, and show orientation. Correct implementation of a digital camera preview requires accounting for the assorted sorts of orientation and adapting because the system’s situations change.

Don’t: assume that facet ratios are static

Do: declare {hardware} characteristic necessities appropriately

  • If you’re declaring your app’s characteristic necessities, seek advice from the steering within the Giant Screens Cookbook. To make sure that you aren’t unnecessarily limiting your app’s attain, you’ll want to use essentially the most inclusive manifest entries that work along with your app.
<uses-feature android:identify="android.{hardware}.digital camera.any" android:required="false" />
<uses-feature android:identify="android.{hardware}.digital camera" android:required="false" />
<uses-feature android:identify="android.{hardware}.digital camera.autofocus" android:required="false" />
<uses-feature android:identify="android.{hardware}.digital camera.flash" android:required="false" />

Don’t: assume window insets are static

  • Giant screens can change ceaselessly, and that features their WindowInsets. This implies we are able to’t simply test the insets when our app is launched and by no means change them.

Do: use the WindowInsetsListener APIs for Views

  • The WindowInsetsListener APIs notify your app when insets change
ViewCompat.setOnApplyWindowInsetsListener(view) { view, windowInsets ->
val insets = windowInsets.getInsets(
WindowInsetsCompat.Kind.systemBars())
view.updateLayoutParams<MarginLayoutParams>(
leftMargin = insets.left,
bottomMargin = insets.backside,
rightMargin = insets.proper,
)
WindowInsetsCompat.CONSUMED
}

Do: use the windowInsetsPadding Modifier for Jetpack Compose

  • The windowInsetsPadding Modifier will dynamically pad primarily based on the given sort of window insets. Moreover, a number of cases of the Modifier can talk with one another to keep away from including duplicate padding, they usually’re mechanically animated.

Don’t: assume the system has a contact display

Do: check your app on giant screens

  • An important factor you are able to do to make sure your app’s expertise is nice on giant screens is to check it your self. If you’d like a rigorous check plan that’s already ready for you, check out the big display compatibility checks.

Do: leverage the big display instruments in Android Studio

  • Android Studio gives instruments to make use of throughout improvement that make it a lot simpler to optimize for giant screens. For instance, multipreview annotations mean you can visualize your app in lots of situations on the identical time. There’s additionally all kinds of pill, desktop, and foldable AVDs obtainable in the Android Digital Machine Supervisor that will help you check your app on giant screens as we speak.

Keep tuned for Google I/O

The following pointers are an ideal start line as you optimize your app for giant screens, and there are much more updates to return at Google I/O on Might tenth. Tune in to look at the newest information and improvements from Google, with stay streamed keynotes and useful product updates on demand.


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments