Android O Developer Preview 2

Android O Developer Preview 2

It feels like Android N (Nougat) just hit the mainstream but Google is already pushing out the next version: Android O to the developer masses. On 17th of May, the second developer preview was released with the final release scheduled for the Q3 of 2017. However, developers can already download the preview on the newer Nexus and Pixel phones. This post will cover some of the most interesting new changes and features in the upcoming version.

Backgrounding limits

For the last couple of years, Android has been fighting to get closer to the battery life of its biggest competitor, iOS. Apple has it way easier because they have total control over the hardware. Android, on the other hand, needs to account for thousands of different devices with different processor architectures. iOS can also optimize its code on a very low level to perform well on a small set of CPU’s they support.

Unlike iOS, Android supports true multitasking. It means that there might be a few applications running at the same time, putting strain on the CPU, RAM, and other components. In Android O, the OS will impose new limits on applications that execute code or use the location in the background. The exact details concerning both background service and broadcast limitations are written down in detail in the official Android documentation. It’s worth noting that most of these changes only concern applications that target the API level 26 and higher.

Regardless of the application’s target API level, Android O will limit the frequency of location updates. As a starting point, the OS allows only a few updates per hour. This limitation only affects app’s that are in the background; foreground applications will have the same access to location updates as before.

Notification Channels

Notifications are about to receive quite an overhaul. A single app can have a separate notification channel for each distinct type of notification they need to send. In turn, users can make per-channel notifications to the following characteristics

  • Importance
  • Sounds
  • Lights
  • Vibration
  • Show on lock screen
  • Override do not disturb

From now on, individual notifications can’t have a unique importance. Developers can define the importance is on the notification channel level on creation time.

Picture-in-picture

Android TV users have already enjoyed the PiP mode since Android N. However, Android O will bring the feature to the mobile users as a special type of multi-window mode. While it’s mostly aimed for video playback, it can be enabled on any activity by setting android:supportsPictureInPicture to true in the manifest file. The only limitation with the PiP mode is that the activity enters a paused state. That’s why developers have to make sure not to pause the playback or any other feature when onPause is called.

The users of Samsung devices are most likely already familiar with this mode, as it has existed in Samsung’s firmware for a few years already.

Android O Picture-in-picture mode

Image courtesy of Google

Autofill Framework

Most modern web browsers implement some sort of autofill functionality for web forms. On a mobile phone, this feature is even more important since filling important data like credit card numbers or emails is a time-consuming and an error-prone job with the smaller screen. Until now, Android app developers haven’t had access to any sort of autofill functionality but Android O is about to change that.

An app can either serve as an autofill service or use a service provided by another app. Existing applications that consist of standard views will work out of the box. However, the developer can take a few extra steps to fully utilize the framework.

Adaptive Icons

Custom launchers are still a big deal to millions of Android users because of the limitations in vanilla Android. However, Google is slowly adding more customization possibilities to the end users. Adaptive icons let the developers define two separate icon layers; background and foreground. The system will then provide the mask to the icon and possibly animate it using a parallax or pulsate visual effect. Without further ado, here are some animations showcasing the feature (from the documentation).

Android O Adaptive Icon Mask Android O Adaptive Icon Mask

Autosizing TextViews

Android O introduces a possibility to “instruct a TextView to let the size of the text expand or contract automatically to fill its layout based on the TextView’s characteristics and boundaries” [Android documentation]. This will allow developers a lot better control over how text acts on different screen sizes and densities. Autosizing can be set on code or XML using Granularity or Preset Sizes.

Granularity allows developers to specify minimum and maximum sizes coupled with the step granularity that defines how much the text increases or decreases in one step. Preset sizes is simply a list of preset sizes that the TextView will translate to once it can fit in the container.

Fonts in XML

Fonts as resources. About time, right! Developers can bundle fonts as resources by adding them to the res/font/ folder. After compilation, the fonts become available in the R file. Developers can then reference them using the new resource type, font.

WebView API Improvements

Android O provides several improvements to the WebView control’s API to improve the stability and security of the applications:

  • Version API
  • Google Safe Browsing API
  • Termination Handle API
  • Renderer Importance API

Version API lets developers choose the version of the WebView package to use inside the application. While it’s not useful in the end-product, developers can easily analyze errors in specific package versions.

Google Safe Browsing API might be familiar to the users of the Chrome browser. If the user navigates to a dangerous, WebView shows a warning. Opting into the feature only requires adding one <meta-data> element to the AppManifest.xml file.

<meta-data android:name="android.webkit.WebView.EnableSafeBrowsing" android:value="true" />
Termination Handle API ensures that the app itself doesn’t crash if the WebView control loses the renderer process due to a crash or system killing it to save memory. Even though the app keeps running after a crash, the WebView object cannot be reused. Here’s an example on how to use the API.

Renderer Importance API should work hand in hand with the Termination Handle API. With it, developers can set the priority for the renderer associated with a WebView. If they set a low priority to the WebView, the system is more likely to kill the process in a low-memory situation.

Pinning Shortcuts and Widgets

iOS users are familiar with the Home screen quick actions that show a context menu when the user holds their finger down on the app icon. Android introduced a similar technique called App Shortcuts on API level 25. Pinned shortcuts are similar but they appear on the launcher as separate icons as seen on the image on the right (courtesy of Google). Users can also pin app widgets that give users access to specific tasks in the application.

Android O App shortcuts vs Pinned shortcuts

Media Player enhancements

MediaPlayer control is about to get improvements to controlling the buffering behavior and seeking to a frame. Also, DRM-protected material can now be played by partially providing the functionality of MediaDrm introduced in API level 18. The current implementation can handle Widevine (by Google) protected local and remote/streaming media files. If you’re interested in learning more about the Widevine DRM technology, check out the architectural overview document here.

Furthermore, Android O introduces a new BufferingParams object that helps the developers get a better control over MediaPlayer’s buffering. The player will use watermarks to make sure that the control initially buffers enough and keeps the buffer filled between high and low marks.

Lastly, fine-grained control over the seeking behavior is achieved by introducing seekMode to the seekTo method. SeekMode defines the frame and accuracy of the seek operation.

Wi-Fi Aware

Wi-Fi Aware (aka Neighbor Awareness Networking or NAN) enables devices to discover and directly connect to each other without any other connectivity in between. The system service forms clusters of devices and the apps, in turn, talk to the service to discover other devices and form connections to them.

After the connection is established, apps can reliably share data between each other. According to Google: “connections are more reliable than Wi-Fi P2P connections and support higher throughput rates across longer distances than Bluetooth connections”.

Android in the Enterprise

It’s clear that Google wants to get enterprise users into the Android ecosystem. With the current BYOD (bring your own device) trend it’s important that the enterprises can effectively manage access, content and even applications on the employees’ devices. For instance, the Corporate Owned Managed Profile (COMP) makes it possible for the device owner to have a separate profile managed by the enterprise which in turn allows apps and policies to be separate. On top of that, there are many other improvements and new features listed and explained here.

Get started with Android O today

Anyone that wants to get their hands on the new Android O can do it today. All they need is a computer capable of running the latest preview version of Android Studio and an emulator. If you still haven’t chosen your mobile development technology, do it now with our helpful guide.

Never miss an update by subscribing to our monthly newsletter!

Summary
Android O Developer Preview 2
Article Name
Android O Developer Preview 2
Description
Android O Developer Preview 2 has been released. Read about the latest changes and improvements coming to your Android phone in Q3, 2017.
Author
Publisher Name
Atos Consulting CH
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *