All articles

Technical

Optimise Android TWAs for Samsung DeX and Desktop

October 9, 2026 · 9 min read

As mobile operating systems become more versatile, Android is increasingly used in desktop environments. Features like Samsung DeX, Motorola Ready For, and the native Android developer desktop mode allow users to connect their mobile devices to external monitors, keyboards, and mice. For productivity tools, document editors, and enterprise SaaS products wrapped in a Trusted Web Activity (TWA), this presents an excellent opportunity to deliver a desktop-class experience from a single codebase.

However, running a TWA inside a windowed, multi-screen desktop environment introduces distinct technical challenges. Web applications built primarily for touch devices must adapt to cursor precision, rapid window resizing, physical keyboard shortcuts, and dynamic system layouts. This article explores how to configure and build your TWA to feel like a native desktop application in these environments.

The Architecture of Android Desktop Modes

When a user launches Samsung DeX or a similar desktop interface, the underlying Android OS changes its configuration. Applications are no longer forced into full-screen mode; instead, they run inside resizable, floating windows that can be minimised, maximised, and snapped side-by-side. Additionally, the system pointer changes from a simulated touch point to a precise mouse cursor, and physical keyboard inputs become the primary interface.

For a standard TWA, this shift can cause severe performance issues or layout rendering bugs if the underlying Android wrapper and CSS frameworks are not prepared to handle the transition. Let us look at the key steps required to ensure your web app performs flawlessly on desktop Android.

Manifest Configurations for Seamless Window Resizing

By default, Android often assumes that legacy mobile applications are not designed to be resized dynamically. If your app does not explicitly declare support for window resizing, Samsung DeX may lock your app into a fixed aspect ratio or force a complete application restart every time the user resizes the window. This causes the service worker to re-initialise, clearing active user states and destroying the application experience.

To prevent this, you must explicitly declare that your TWA can handle window resizing and orientation changes dynamically. This is configured in your Android Manifest file within the main activity tag.

Preventing Page Reloads on Resize

You must ensure your TWA activity is configured to handle configuration changes natively instead of letting the Android OS recreate the activity. Add the following attributes to your main TWA activity node:

android:resizeableActivity="true" android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden|navigation"

By setting resizeableActivity to true, you tell the system that your layout can adjust to any window dimension. The configChanges attribute ensures that when a user snaps your app window to half-screen or resizes it manually, the browser instance inside the TWA simply receives standard web window resize events rather than forcing a full application reload.

Enhancing the User Interface for Desktop Inputs

Once your TWA is running inside a resizable desktop window, your web application must adapt its user interface. The transition from touch input to pointer input requires modifications to both your CSS and JavaScript layers.

Use CSS media queries to detect whether the user has a precise pointer device. This allows you to scale down large, touch-friendly buttons to a size more appropriate for desktop environments, and introduce subtle hover animations that guide the cursor experience.

@media (pointer: fine) { button { padding: 8px 16px; font-size: 14px; } .nav-item:hover { background-color: #f0f0f0; cursor: pointer; } }

Keyboard Shortcuts and Focus Management

Desktop users expect standard keyboard shortcuts to work within your application. Since your TWA has full focus when active, you can listen for modifier keys directly in your JavaScript runtime. You should map common operations like saving, searching, or undoing actions to keyboard events.

Additionally, ensure that focus states are clearly defined. Users navigating your TWA with a physical keyboard tab key must be able to visually identify which form fields, buttons, or navigation elements are currently active. Do not use global CSS resets that disable the outline property without providing a custom focus state alternative.

Managing Window State and Page Visibility Lifecycle

In a desktop environment, users frequently switch between multiple active applications, leave your app running in a background window, or minimise it entirely. Your TWA must handle these transitions efficiently to conserve system memory and device battery without losing progress.

Use the standard Page Visibility API within your web application to detect when your window is minimised or hidden behind another application window. This allows you to temporarily pause intensive background operations, close active WebSocket connections, or reduce the polling frequency of your API calls.

document.addEventListener('visibilitychange', () => { if (document.hidden) { // Pause resource-intensive processes stopTelemetryPolling(); } else { // Resume active session processes startTelemetryPolling(); } });

Desktop Compatibility Comparison Matrix

Designing for desktop Android requires balancing standard mobile behaviors with desktop conveniences. The table below outlines how specific hardware features should be treated differently depending on the operating state of your TWA.

FeatureStandard Mobile TWA BehaviourSamsung DeX / Desktop Behaviour
Pointer InteractionsTouch gestures, swiping, pull-to-refreshHover states, right-click menus, mouse wheel scroll
Keyboard InputVirtual soft keyboard, auto-capitalisationPhysical keyboard, layout modifiers, tab navigation
Window LayoutStrict vertical or horizontal orientation lockFluid resizable window containers, split-screen snap
Drag and DropLong-press to select text or initiate mobile dragNative HTML5 drag-and-drop support for file attachments

By implementing these adjustments, your web-to-app conversion remains lean and efficient on standard mobile phones, while instantly elevating into a professional, production-grade desktop client whenever the user connects to a monitor or opens Samsung DeX.

Ready to ship your Android app?

Paste your PWA URL, get a signed APK and a Google Play ready AAB in minutes.

Build my app