It’s been around two weeks when Google announced Android O preview. This is again exciting time of the year when you can try out all new features of Android’s upcoming OS version Android - O (what is your guess about ‘O’?) before it is released and keep your apps ready for new OS version support. As it happens with every Android OS version, Android O also brings many new features and some optimizations techniques to make better apps. Here are some of the new features -
Background Limits - A few years back, Android background service implementation was one of the comparison points with iOS. Android Nougat introduced some changes in background service implementation and now with Android O preview, there will be major changes in it. Background service implementation will have certain limitations divided into three major areas viz. implicit broadcasts, background services and location updates. All these changes are introduced to limit background usage and improve interactive performance by improving RAM usage.
- Implicit broadcasts -
- Apps targeting Android O will no longer receive implicit broadcasts in the background to most manifest declared receivers.
- Some of the exceptions to implicit broadcast change will be
- USB_DEVICE_ATTACHED etc.
- Apps can receive implicit broadcasts only when an app is active.
- There is no change in the explicit broadcast that targets application package registered in the manifest. It will work as it is.
- Background services -
- Android-O puts a limit on how long background service can stay alive once the app goes to background. Background service can now only run for short time after the app has no longer visible activity or any foreground service.
- startService or service PendingIntent will throw an IllegalStateException when an app is not in the foreground.
- Above mentioned background service changes do not impact foreground services. For example, foreground services which require persistent notifications, work as usual and there is new service to start service in Foreground which is NotificationManager#startServiceInForeground.
- There is another catch though, there will be some changes to background services even if your app does not target Android O such as Wakelock will be released when your app enters the cached state where there is no active Android component.
- Location updates -
- Android play store is flooded with many location-based apps as Android till date supported background location updates. Android-O restricts background location updates. Now your app can request background location updates just a few times per hour.
- Location updates in foreground services are not impacted by this change. So apps which do location tracking in real time using foreground service will work as it is.
- Your background app can take advantage of another foreground app which is getting location updates. It can then get location updates with the same frequency as that of foreground app.
User Privacy - Android always emphasis on protecting user’s privacy. Android-O also does certain modifications to protect user’s privacy.
- ANDROID_ID Change - There are some changes in Android ID settings for apps and it will be noticed under Settings.Secure.ANDROID_ID. Prior to Android-O, Settings.Secure.ANDROID_ID was same across all apps but now with Android-O, ANDROID_ID will be different per app per user. This value will persist across app reinstalls. Google still recommend using user-resettable advertising id provided by Google Play service for simple, standard system to help monetize the app
- Account Access -
- App will not be able to get account access directly using GET_ACCOUNTS permissions. App will have to rely on account choosing activity.
- With Android-O, account owners can now choose whether accounts should be visible to other apps. Accordingly, Account choosing activity API will be updated.
Notifications Channel - Android-O adds notifications channel to give a user more control over notifications and app developer more flexibility with notifications to be sent.
- The app developer has to use Notification channel for Android O otherwise notifications will not be shown for the app.
- Notification channel is named category of notifications from the single app. You can use notification channels to have different categories of notifications.
- User can block category or alter its behavior like change importance, add vibrations or lights, an ability to snooze, set timeouts to cancel etc. User can long press on notification to bring out notification channel settings.
- Check implementation details of notification channel.
Autofill framework - Chrome browser is a well known example where users can avail autofill feature while filling out repetitive information on the web. Android-O introduces Autofill framework so Android apps can make form filling tasks easy to the users.
- With Android-O, now user can select autofill app similar to the way keyboard app is selected.
- Autofill app is responsible for storing and securing user data such as name, addresses, phone numbers, email, password or even credit card information etc.
- New View API is also introduced in custom views to expose metadata to Autofill framework.
- Click here for more details about autofill framework
Picture-in-Picture - Picture in Picture (PIP) mode allows your video activity to play in pinned window mode when another foreground activity or app is running. Earlier to Android O, PIP was supported only for Android TVs but now you can use PIP feature in Android O targeted apps on other Android devices as well.
- To implement the Picture-in-Picture feature, all app has to do is to call the enterPictureInPictureMode method from resume or pause state of your media activity.
- You can set picture in picture aspect ratio of mobile devices along with custom remote actions that allow user to interact with picture in picture activity using setPictureInPictureArgs(PictureInPictureArgs);
- Make sure you continue playback in paused state if you are adding PIP support in your app.
Multi-display support -
- Rather than having an app explicitly use the presentation API, regular activities can now be launched on secondary displays.
- These displays have per display based configuration and resource management. This means some of the parts of a configuration such as a screen width DP, screen height DP layout, density DP will be set accordingly to the display on which activity currently resides.
Font resources - Finally, Android-O makes custom font implementation easy with font resources support.
- Fonts are fully supported resources type in Android-O.
Now app developer can get font by just calling the getFont(int) method to get font by ID.
Typeface font = mResources.getFont(R.font.myFont);
- You can also declare entire font family in XML file, declaring font style, weight along with font resource.
- Android O will now support Bluetooth CODECS LDAC CODEC.
- Wi-Fi Aware is a new feature added in Android-O which was previously known as Neighbor awareness networking (NAN). Devices with required hardware will be able to communicate over Wifi without an Internet access point.
- Android-O adds ConnectionService APIs so third-party calling apps can work seamlessly with system UI and other audio apps.
WebView API enhancements - We will see a lot of webView API enhancements to improve app’s stability and security in Android-O. Following set of APIs are introduced in Android-O for webView -
- Version API
- Google Safe browsing API
- Termination Handle API
- Renderer Importance API
Pinning shortcuts and widgets - If you are a big fan of 3D touch feature in iOS, you will love pinning shortcut feature of Android-O.
- Now app user can access key features of the app directly from app icon from launcher screen.
- Developers can pin shortcuts to specific tasks to app icon on launcher screen yet giving control to a user whether to see pinned shortcuts for that or not.
- Launcher will show confirmation dialog asking user’s permission to pin the shortcuts. If a user declines, launcher app will not show pinned shortcuts.
- Similar to pinned shortcuts, users can pin widgets to the supported launcher.
- Just remember, pinned shortcuts and widgets will work on devices running Android-O with launcher supporting pin feature.
Adaptive icons - Android O can now display a variety of shapes for app icons across different device modes. Display of icons depends on OEM mask. Click here for more details about Adaptive icons.
So Android developers, get ready to explore Android-O preview for these and many other features.