Adapt Your App to Foldable Devices for an Optimal User Experience
foldable technology for mobile is a groundbreaking experience not only for users but also for developers. the presence of many form factors like immersive display, app continuity, flex mode and ux optimization challenge developers to think outside of the box to adapt to this technology. in this blog, we discuss a checklist to provide a better understanding about the adaptation, modification and design changes that are required. so, let's go through each point, one-by-one. large screen optimization samsung foldable devices have two different physical screens: the cover display and the main display. as the cover display is much smaller than the main display, large screen optimization is one of the key areas of designing ux for foldable devices. in a nutshell, your app can utilize the extra space in the main display by showing more information. just having a different ui design with the same information can do the trick of optimization as well. large screen optimization of a note app to implement this scenario, define different layout files for each display using the alternate resources option. for example, if you want to define a different ui for the main display, create a new directory named layout-sw600dp under the res directory and then create an xml file named activity_main. then add the layout code as required. ui is designed separately for the main display and the cover display flex mode optimization in galaxy z series devices, samsung introduced a new mode called flex mode. this mode allows users to use apps while the book-like phone is partially folded. creative design can really make your app stand out from others in flex mode. google duo app in flex mode in galaxy z series devices using google’s new jetpack library, windowmanager, you can detect the current posture of a galaxy z series device and update the ui accordingly by following these steps: step 1: add the dependencies in the build.gradle. implementation "androidx.window:window:1.0.0-alpha01" step 2: define a windowmanager instance. val windowmanager = windowmanager(this, null) step 3: register the devicestate change listener. the listener notices changes in the device state (for example closed, opened, half_opened). windowmanager.registerdevicestatechangecallback( mainthreadexecutor /* executor */, callback /* consumer<devicestate> */ ) step 4: write a callback function to check devicestate.posture to get the current posture of the device. if the posture is posture_half_opened, the app ui gets updated for flex mode. val callback = consumer<devicestate> { devicestate -> if (devicestate.posture == devicestate.posture_half_opened) { // display is folded, show split ux } else { // display is not folded, show full screen ux } } check out the codelab challenge on flex mode for a more hands-on experience. app continuity while folding and unfolding the device, the app must prevent data loss thus ensuring its continuity. this is achievable by using the onsaveinstancestate() method. first, save the data to retain the current state with onsaveinstancestate(). @override public void onsaveinstancestate(bundle savedinstancestate) { //save the current state } then, restore the data in the oncreate() function. @override protected void oncreate(bundle savedinstancestate) { if (savedinstancestate != null) { //restore the previous state } } stopwatch app continuity while unfolding device to have a better understanding of implementing app continuity, see the codelab challenge on app continuity. responsive ui layout to adapt to new form factors such as a diverse aspect ratio, flex mode, multi-window, and pop-up window, utilize the following guidelines : design a responsive ui layout for your app using constraintlayout. define the activity of your app as resizable, to ensure the maximum compatibility of your app with both the cover display and the main display of the device. set the resizableactivity attribute to true in manifest.xml. <activity android:name=".mainactivity" android:resizeableactivity="true"> … </activity> responsive layout of the spotify app cutout and punch hole of the main display the main display of a galaxy z fold is covered by an area on the top-right side called the “l-cut” whereas the galaxy z fold2 and fold3 have a punch hole in the upper right side and the galaxy z flip devices have a punch hole in the middle. some portion of your app’s ui could be covered by the l-cut or the punch hole. content is covered by the l-cut in a galaxy fold device in landscape mode to avoid such a scenario, depending on your ui content style, define a display cutout mode. for example, the content is letterboxed in landscape mode whereas it is rendered into the cutout area in portrait mode by default. define the display cutout mode in the style.xml as shortedges so that your content is rendered into the cutout area in both portrait and landscape modes. <item name="android:windowlayoutindisplaycutoutmode">shortedges</item> display cutout in the default mode and the shortedges mode, respectively last but not the least, you can test your app on our device cloud, samsung remote test lab, to make sure you have implemented all the checkpoints discussed in this blog. you can also participate in our codelab challenges to have a clear understanding of the implementation details. in this blog we have discussed about how to adapt your app for foldable devices. we hope it is a good guide for you to start with. you can also check out samsung’s official documentation and reach out to our developer community if you have any queries.