Exaud Blog
Blog
How to Adapt Your App to Android Nougat
Google launched in the past month a new version (7.0) of Android, named Nougat. This… Posted onby André LopesGoogle launched in the past month a new version (7.0) of Android, named Nougat. This new version brought some new visual features as Multi-Window Mode, Display Size, Bundled Notifications and Notification Direct Reply (among others).
In this article I want to share some of the technical challenges we encountered during our work at Exaud, in order to make sure our applications had no conflicts with this newest Android version and some of its new features. I divided the potential situations requiring attention in groups, by feature. But first, let’s make sure we all know how to pronounce the word ‘Nougat’ correctly.
About The Name
Nougat is a chewy sweet made from sugar or honey, nuts and egg white.
Nougat is not pronounced Nougáte ‘/noʊ-gæt/’ or No-gat ‘/noʊ-ɡʌt/’ as I
originally thought and verbalized (as a Portuguese guy). So, after going
back to search for the right pronunciation, I found out that, obviously, it
is pronounced Nugat ˈ/nʌɡət/’.
Adapting your app to Android Nougat
Changes on AndroidManifest
It’s highly advisable to increase the targetSdkVersion to reflect the
adaptation of the app to the newest Android Version (this will indicate that
this app was already tested on Nougat).
targetSdkVersion 24
In order to to make some changes regarding the adaptation, compileSdkVersion should be increased (this will allow to do all required code changes in order to adapt the app to the Nougat).
compileSdkVersion 24
Display Size
New Option on Nougat (accessible via Accessibility Options) that can
increase or decrease the size of all items in the screen.
Situation: Display Size might change
the sizes of items to unfitting sizes.
Solution: Review all screens to detect
images that originally fitted perfectly but with changes on Display Size
might need an adapting container to match the available space.
Multi-Window
New feature on Nougat that allows two apps to be displayed side by side. As
usual, Google provided excelent resources to teach developers about what to
expect and how to handle the new features:
Designing for Split-Screen Multi-Window
(Android Development Patterns S3 Ep 1)
Situation: Splitting the screen with
another app will reduce to half the available space.
Solution: Some containers might require
a ScrollView to be functional.
Situation: Rotating the screen while in
Split-screen mode will issue a rotation on single-orientation apps.
Solution: Handling the unexpected
rotation on Nougat and higher versions or restricting altogether the
Split-screen mode with the flag android:resizeableActivity=”false” on
AndroidManifest.xml
Situation: Entering the Split-screen
mode while in portrait will show the app in landscape mode.
Solution: Reviewing if there is any
code handling a specific rotation. If not present such handling, this might
not be an issue.
Lifecycle Changes
With the Split-screen mode an app will now go through onPause() and
OnResume() states without ever going to onStop() state, when the focus
between the two apps in the screen is changed.
Situation: onPause() and onResume()
will be called without the app ever losing visibility.
Solution: Making sure that onPause()
and onResume() don’t assume that the app was not visible when paused. This
might require a change of the lifecycle states for Nougat and higher
versions.
You can read more about this issue here: UI Updates in a Multi-Window World (credits to Pedro Teixeira for notifying me about this situation)
Bonus
Implement Drag and Drop between applications
Now that we can have two apps side by side, you can take advantage of this
cool feature, by dragging a text from one app to another. In order to test
this, you need to do a long press on a EditText on a external app (try to do
a second long press after the COPY and PASTE options appear, if you can’t
seem to select the text to drag) and drop it on your application.
In your app, you should apply a DragListener to the container where you expect the text to be dropped.
- editText.setOnDragListener(new View.OnDragListener() {
- @Override
- public boolean onDrag(View view, DragEvent event) {
- if (event.getAction() == DragEvent.ACTION_DROP) {
- if (event.getClipData() != null && event.getClipData().getItemAt(0) != null) {
- CharSequence text = event.getClipData().getItemAt(0).getText();
- editText.setText(text);
- }
- }
- return true;
- }
- });
Let’s hope this tips will improve your work in the adaptation of your app to Nougat.