Tag Archives: Background Processes

How to Optimize GPS and Background Processes for Android Oreo

As our past article Android Oreo Serves Up the Sweets will show, Android Oreo lived up to expectations upon release and gave both consumers and app developers plenty of enhancements to enjoy.

However, for app developers, enhancements to the UI aimed to conserve battery life affect GPS services and require changes to the code in order to optimize pre-existing apps for the new OS. Specifically, Android Oreo restricts apps that are running in the background with limited access to background services. Additionally, apps can no longer use their manifests to register for most implicit broadcasts. When an app is in the background, it is given several minutes to create and use services, but at the end of that time slot, the app is considered idle and the OS will stop running background services.

These changes directly affect apps with geolocation functionality. Android Oreo limits how frequently apps can gather location in the background. Background apps can only receive location updates a few times each hour. The APIs affected due to these limits include Fused Location Provider, Geofencing, Location Manager, Wifi Manager, GNSS Measurements and GNSS Navigation Messages.

Apps that currently use location services in previous Android OS’s will require an update to optimize for Android Oreo. Apps that use location services range anywhere from navigational apps like Waze and Google Maps to social media apps like Twitter, and food apps like Yelp and Seamless.

For apps that require frequent location updates, increasing the usage of the app in the foreground will ensure that the app gets frequent access to location information. In order to program this, developers must implement startServiceinForeground() instead of startService() in Activity class.

In Service class in onStartCommand(), developers can use the following code:

Screen Shot 2018-05-07 at 12.46.57 PM

Via StackOverflow

When foreground services running in the background consume high energy, Oreo fires an automatic push notification to the user informing them of the battery-consuming service. With the push notification in place, app users are more likely to uninstall apps that track location without conserving battery life, putting the onus on software developers to deliver battery-efficient apps. One of the biggest issues facing some app developers is ensuring that battery life is not sucked as a result of tracking location in apps. Check out our full rundown of how to build battery-efficient geolocation apps for supplementary reading.

The results of the limits put in place with Android O are increased battery life for the user and the necessity for app owners to consider how their apps interact with location information. Retaining a thorough understanding of how location information will be retrieved and used through out the development process ultimately benefits both software developers and consumers with better UI and more energy efficient processes.

Android Oreo Serves Up the Sweets

Like the candy, Google’s newest delectable dessert-themed operating system Android 8.0 Oreo offers the best of both worlds: crunchy cookie goodness of versatile functionality and the creamy frosting of beautiful UI and presentation.

PROJECT TREBLE 

Project Treble is one of the major aspects of Android Oreo that makes it a full 1.0 update. Project Treble is designed to reduce device fragmentation by making it easier for hardware manufacturers to issue updates on Android devices. The architecture redesign modularizes the Android OS away from the drivers and other hardware-specific code. By making it easier for manufacturers to update Android devices, Project Treble makes accessing the latest Android OS from your devices  easier than ever.

HIGH-PERFORMANCE BLUETOOTH AUDIO

Android Oreo is loaded up with BLUETOOTH 5 and LDAC, making Oreo capable of supporting audio quality that surpasses what the vast majority of high-end audio equipment can reproduce.

LDAC is a codec that supports the transfer of 24 bit, 96kHz audio via Bluetooth. The closest competitor is Qualcomm’s aptX HD which supports 24 bit, 48kHz technology. LDAC was created by Sony, who donated the codec to Android for Oreo as a part of the core AOSP code for other OEMS to implement.

Whereas previous iterations of Bluetooth offered a range of 50m-100m outdoors and 10m-20m indoors, Bluetooth 5 can reach up to 200m outdoors and 40m indoors. Additionally, Bluetooth 5 BLE doubles Bluetooth 4.x BLE’s data transfer rate with up to 2Mbps. The kicker is: Bluetooth 5 actually utilizes up to 2.5 times less power while increasing range and speed.

BATTERY LIFE

The Android Oreo update includes multiple initiatives designed to improve battery life. Background execution limits have been enacted to limit requests to scheduled windows of activity, resulting in longer battery life and less strain on the device by inactive apps.

Android Oreo places two major limitations on what apps can do while users aren’t directly interacting with them:

  1. Background Service Limitations limit the use of background services by idle apps. This does not apply to foreground apps, which are defined as apps with visible activity, apps with a foreground service, or apps that are connected to another foreground app.​
  2. Broadcast Limitations prevent apps from using their manifest to register for implicit broadcasts. Apps can still use their manifest to register for broadcasts at runtime and for explicit broadcasts targeted specifically at their app.

For the most part, app developers can work around these limitations using JobScheduler jobs. Android has also made several improvements to JobScheduler.

Background execution limits will have a major impact on the functionality of existing and future apps, check out a full breakdown of the new functionality directly from Android.

Additionally, Android Oreo comes with Vitals. Vitals is an initiative by Google that improves system performance and stability by offering developers various tools to monitor app usage on a device. Vitals enables developers to  optimize their apps for improved battery life and performance.

UI

Google’s strategy with OS updates has become more and more minimal in recent years. The last major visual OS overhaul was enacted by Google in Android 5.0 Lollipop. Android Oreo does not change the name of the game, but offers a variety of UI improvements.

DOWNLOADABLE FONTS: Android 8.0 Oreo offers support for apps to request fonts from a “provider” application, reducing the amount of disk space spent by apps on storing font libraries individually.

NOTIFICATION CHANNELS: Notifications have always been one of the strong suits of Android Operating Systems. With Android Oreo, app notifications must be sorted by the developer into channels based on type, so that the user can then customize what types of notifications they would like to receive and how they receive them.

For example, users can modify characteristics of notification channels that apply to all notifications in that channel, including:

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

PICTURE IN PICTURE MODE: Oreo ports Android’s famous “Picture-In-Picture Mode” for phones and tablets. Picture-In-Picture Mode allows users to view multiple apps at the same time. It is most handy for watching video or having a video call while using another app.

TAKEAWAY

Overall, Android 8.0 Oreo delivers the goods. It’s sleek, supports the best audio quality available, allows more UI customizability, saves battery life, and it’s a major step toward conquering device fragmentation which has plagued Android since its inception.