Android Oreo: New Features Developers Should Know
Every new release of Android brings out a lot of new features that audience are eager to try, so we developers have the responsibility of updating our apps to include these new features, thereby keeping our users happy. The Android 8.0’s major release came out with the name of a delicious cookie, ‘Oreo’. Android 8.0 (API level 26) brings many API behaviour and system changes along with the new features and capabilities.
Android Oreo brings a lot of new features such as picture-in-picture, auto-fill, integrated Instant Apps, Google Play Protect, faster boot time, and much more. While on the external side it may lack some visual changes and loaded with usability improvements and elegance.
Let’s see what are the new features that every developer should be aware of.
For earlier Android versions It was not possible to Autofill forms, only chrome and some other web browsers were having this facility. This feature is very helpful for users in filling long forms. Now it is available in the Android Oreo and your apps can take advantage of it. All you need is to provide some metadata to the OS to autofill the input data. Example usage; provide AUTOFILL_HINT_USERNAME for a username or AUTOFILL_HINT_CREDIT_CARD_NUMBER for a credit card number to be filled in that specific edit text box.
Background Execution Limits
A runnable app can be in one of two states on an Android device: it is either a foreground app, which is currently interacting with the user; or it can be a background app, an app which is not interacting with the user.
Foreground apps can be battery drainers, but that is OK, as long as the user has made a choice to play a game or watch a movie and is expecting a related drop in the battery level. However that’s not the case with the background tasks. Since they are not interacting with the user, the user has little or no knowledge of what these apps are doing and how much they are draining the battery.
For limiting the battery drain, Android 8.0 Oreo implements background execution limits, a mechanism which limits certain behaviors by apps that are not running in the foreground.Which means if an app, say a social media app, wants to check whether there are new posts available, even if it isn’t running in the foreground, then it can no longer just use a background service which checks with the cloud, as this background service will be stopped under the background execution limits mechanism. Instead the app should replace the background service with a scheduled job, which is launched periodically, queries the cloud, and then quits.
● Switch to Job Scheduler
New Android 8.0 introduces a number of improvements to the JobScheduler, which are designed to help apps move from using background services to scheduled jobs. The JobScheduler is an API for scheduling various types of jobs that will be executed in your application’s own process.
Now with the Android Support Library 26.0.0, a new JobIntentService class has been introduced, which provides the same functionality as IntentService but uses jobs rather than background services when running on Android Oreo.
Latest release of scheduled jobs now support several new constraints including:
isRequireStorageNotLow(): which ensures that a job does not run if the device’s available storage is low.
isRequireBatteryNotLow(): which stops a job from running if the battery level is low.
The reasoning behind these changes is to stop apps taking up too many system resources while in the background. What is interesting is that by default Background Execution Limits only apply to apps that target Android 8.0. However, users can enable these restrictions for any app from the Settings, even if the app was built for a version of Android prior to 8.0.
Another approach for performing background tasks is by using the below given library, which is backward compatible:
Android Oreo brings some new user experience with Notification changes. Many new functionalities are added to notifications. Users can now long press on the individual icons to get the notifications from that app along with app shortcuts.
● Notification Channels
Notification channels allow you to group related notifications into dedicated channels, and then define a different behavior for each of these channels. If your app targets API level 26, then notifications channels are mandatory.
You cannot post a notification without specifying a valid notification channel ID, so you’ll need to create at least one notification channel for your app. However, for the best results you should create a channel for each distinct “type” of notification that your app creates, and then assign different characteristics to each channel, for example different vibration patterns, alert sounds, and levels of importance (in Oreo you can no longer set a priority level for individual notifications). However, the user can modify a channel’s characteristics, so there’s no guarantee that your channel will have these exact settings forever.
You create a notification channel, by following steps:
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//Define the channel’s ID//
String channelId = “my_notification_channel”;
//Define the channel’s user-visible name//
CharSequence channelName = getString(R.string.channel_name);
//Set the channel’s priority level//
int channelImportance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, channelImportance);
//Define your notification channel’s initial characteristics//
//Submit the notification channel object to the notification manager//
When you’re creating a notification, you specify the channel this notification belongs to, using setChannelId():
String channelId = “my_notification_channel”;
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setContentText(“You’ve been notified!”)
//Assign this notification to the channel we created earlier//
● Notification dots
Notification dots Notification dots for displaying dots, or badges, on app launcher icons. Notification dots reflect the presence of notifications that the user has not yet dismissed or acted on. Currently this feature is available as third party launchers, but now it’s a functionality in the operating system.
More to come……