Have you ever considered what it’d be like to try and carry your tablet around with you in your pocket? It doesn’t sound too comfortable, does it?!
We’d need extra large pockets, for a start, would most probably have to adopt a silly walk and you would have to forget sitting comfortably for the foreseeable! The future of the smartphone, however, looks to become increasingly more foldable – capturing the same rich user experience you get with tablets without losing the levels of comfort you get from carrying your smartphone.
Android developers have seen their apps run on a wealth of devices over the years. It would seem that we’re now looking to welcome another into the fold, excuse the pun!
After many months of rumours, last month Samsung presented a prototype of their new smartphone for 2019 – a foldable device! Foldable devices run much like today’s smartphones; Samsung’s offering, the foldable Galaxy X, has two screens – one that is typical smartphone size and another that converts the device into a tablet when unfolded.
If you’ve been living under a rock and have thus only just heard about it, you can head over and watch the Samsung keynote speech at their Developer Conference.
Looks pretty interesting, huh?!
I’m definitely looking forward to seeing what other foldable devices enter the market over the next few years. So, we know how they’re supposed to work but how can we, as developers, create apps for these foldable devices?
Luckily for us, Google has our back!
At the annual Android Dev Summit last month, they discussed just that at their ‘Is Your App Ready For Foldable Phones?’ talk. There is also advice on how you can get your app ready for foldable technology on their website.
If you haven’t got the time to check out the above, however, there’s no need to worry as we’re going to summarise and explain the basic things you need to consider when developing for a foldable device in this very post! Don’t say we don’t spoil you.
The first thing we need to consider is Screen Continuity. What does that mean?!
Imagine your user is looking at Google Maps from the folded position. With this new technology, you should be seeking to offer the user a continuous experience when they then go to unfold their device. Makes sense, right?!
When they unfold the device, they should be able to somehow dive deeper into their current task in order to get a richer experience. In the case of Google Maps, for instance, the user could perhaps expect to see more of the map when the device extends.
How can we expect to achieve this outcome? Take a seat and I’ll show you.
A configuration change is triggered when the device is unfolded at:
In order to offer the best user experience, you should declare the following in your AndroidManifest file:
To handle that configuration change, you should use onSavedInstanceState and ViewModel to recover the state where the user was and to re-calculate what is needed.
Or, if you don’t want to restart your Activity, you can handle it via:
The second thing we need to consider is the Lifecycle in Multi-Window. At this current moment in time, only one Activity can be resumed at the same time. In the next Android Version, however, Multi-Resume will be mandatory so it’s best to look ahead and understand what that means for the development process.
Multi-Resume would mean that all the Activities that are on the screen would be able to be resumed at the same time – as opposed to just resuming one Activity and pausing all of the others.
You can opt-in to start looking at how Multi-Resume will exist in Android P via this Manifest flag:
You need to be aware that more than one Activity from the same app will be able to be resumed. Make sure you check that you’re handling that sufficiently and also be sure to check that any third party libraries you’re using are handling it sufficiently too, in order to avoid situations where it stores the resumed Activity in a Singleton, etc.
The third thing we need to consider when developing apps for foldable devices is Multi-Display. Starting with Android O, an Activity can be launched on a display that is not the default one.
If your app is moving to a secondary display, you should think about what Context you’re using as the Activity Context is not the same as the Application Context. For example, if you use the Application Context to retrieve the default display it will give you different values to the ones retrieved from the Activity Context.
In this instance, the Activity Context would give you the current display where the Activity is displayed and the Application Context would give you the default one.
When the current display is changed, onConfigurationChanged will be called if the Activity handles the configuration change and onCreate will be called when this one is relaunched.
If you want to use multiple screens, you may want to use the following snippets:
To support multiple instances, you should think about experiences where you can build with multiple Activities interacting with each other.
You’re now just about ready to start developing for foldable devices!
If you want to test your app to check that you have made the best user experience for foldable devices, Samsung will be releasing an emulator at some time this month allowing you to do just that. They also have an app design guide for foldable devices which is also worth taking a look at!
We can’t wait to see what new devices come out in 2019, which new ways of using them will be introduced and how Android development will thus adapt to these new modes of interaction.
We will, of course, keep you updated on all stages of the evolution process!
What’s your verdict on foldable technology? Is it the future or a fad? Tweet us your opinions!
If you’ve got some time to kill, there are a whole host of posts for you to read – from how to efficiently manage your Android app’s memory to how to create a functional and well-designed Android app.