This presentation attempts to summarize content the speaker thinks is important for Nigerian Developers to take their apps to the next level. It contains a summary of specific Android sessions delivered at Google I/O 2016 and was presented at the Google I/O Extended 16 event in Lagos, Nigeria.
6. Related Google I/O session
Android battery and memory optimizations
(https://goo.gl/cVDwub)
Doze mode (M vs. N)
7. Doze mode (M vs. N)
Android battery and memory optimizations Android battery and memory optimizations
8. Android battery and memory optimizations
Battery life and Memory
Reduce - Reduce all background activity
Defer - Defer background activities to when device is on charger
Coalesce - If it can’t be deferred, coalesce it with other background
activity to avoid overhead
9. Android Battery and Memory optimizations
Alternatively,
Use the Android JobScheduler API on L+ devices
or the Firebase JobDispatcher library on Pre-L devices
10. Android JobScheduler
An API for scheduling various types of jobs against the
framework that will be executed in your application’s
own process
11. Firebase JobDispatcher
GCM Network Manager === Firebase JobDispatcher
A new open source SDK for scheduling and executing
background activity on Android. Coming soon for iOS.
Available on devices with Google Play Services installed
12. Getting started with JobScheduler/JobDispatcher
I/O Codelab
g.co/codelabs/jobscheduler
14. Related Google I/O sessions
Lean and fast - putting your app on a diet
(https://goo.gl/Yro9EZ)
Image compression for Android Developers
(https://goo.gl/bDs011)
Putting your app on a diet
16. Images...
PNG
JPG
WebP - A modern image format that provides superior
lossless and lossy compression for images on the web. Get it
here:
https://developers.google.com/speed/webp/download
VectorDrawable - Creates a drawable based on an XML
vector graphic
17. Optimize images
<4.0: Use webp images instead of jpg and transparent
pngs
>4.2.1: Use webp images instead of pngs
>5.0: Use VectorDrawable
<5.0: Use VectorDrawableCompat
23. Related Google I/O sessions
What’s new in Android
(https://goo.gl/7BsfNj)
What’s new in Android development tools
(https://goo.gl/ldgHVG)
Development tools
There were a lot of new releases for Android at I/O this year. There was the Android N Developer Preview 3, Android VR, Android Studio 2.2 Preview, Android Wear 2.0 and so on. This is all good, but I tried to go through I/O from a Nigerian developer’s perspective. Nigerian here meaning that the developer lives and works in Nigeria, and develops apps for the Nigerian market. We all know how our market is… expensive internet connection, no power etc etc. I tried to curate content that I thought would help Nigerian devs build better apps and think more about their users.
So, I was able to divide my findings into two; releases that benefit the user and releases that benefits the developers. This is not an exhaustive list, but all the content is already available online or on the DVDs if you ordered for them so you can always go back to them. I bunched a lot of things that I think I will be able to talk about in about 45 minutes together, so, fasten your seat belts.
We’ll start with the users, because, users first.
In Doze mode, the system attempts to conserve battery by restricting apps' access to network and CPU-intensive services. There was a session dedicated to this topic at I/O where doze mode in M and N was completely broken down
I took screenshots of this images from the slides at the Android battery and memory optimizations talk.
In M, Doze mode becomes active, if a user leaves a device unplugged and stationary for a period of time, with the screen off.
Doze mode works in N even when the app is not stationary unlike M where it worked only on stationary devices (refer to Android Battery and memory optimizations). Maintenance window where device is woken up temporarily to perform all the blocked tasks and then goes back to sleep for even longer and that cycle continues until the screen is on or the device is plugged.
Most of the power goes when the screen is on for whatever reason, and then when the screen is off, wakelocks, services, background tasks
Impact of all those activities happening at once in the maintenance window affects battery life and leads to much impact on the RAM of the device. You won’t want users detecting that your app is the one that drains their battery and uninstalls it. In this period where fuel now costs #145 per litre.
*Tell mum story*
They are the preferred way of doing work while your app isn't in the foreground.
The framework will be intelligent about when you receive your callbacks, and attempt to batch and defer them as much as possible. Typically if you don't specify a deadline on your job, it can be run at any moment depending on the current state of the JobScheduler's internal queue, however it might be deferred as long as until the next time the device is connected to a power source.
GCM Network Manager has been renamed to Firebase JobDispatcher.
Battery Historian is a tool to inspect battery related information and events on an Android device running Android 5.0 Lollipop (API level 21) and later, while the device was on battery. It allows application developers to visualize system and application level events on a timeline with panning and zooming functionality, easily see various aggregated statistics since the device was last fully charged, and select an application and inspect the metrics that impact battery specific to the chosen application. It also allows an A/B comparison of two bugreports, highlighting differences in key battery related metrics.
Apart from saving our users battery life, another thing we want to help them do is save their data. So that they can actually download your app instead of passing it around on Flash Share. Moment of truth… How large was the last Android app you built?
This image was taken was from the presentation at the Lean and Fast session.
WebP is a modern image format that provides superior lossless and lossy compression for images on the web. Using WebP, webmasters and web developers can create smaller, richer images that make the web faster. WebP lossless images are 26% smaller in size compared to PNGs. WebP lossy images are 25-34% smaller than comparable JPEG images at equivalent SSIM quality index.
Convert your favorite collection from PNG and JPEG to WebP by downloading the precompiled cwebpconversion tool for Linux, Windows or Mac OS X.
VectorDrawable - think svg for Android
VectorDrawableCompat makes VectorDrawable available on all devices from Android 2.1 and above
How do we decide when to use these images?
According to the Image Compression talk by Colt, we have to profile our code, make a decision based on evidence, optimize for your users in every case. Know when to use certain types of images (PNG, JPG, VectorDrawable, WebP images).
Minify Enabled - Remove unused code. Use @Keep annotation if you don’t want AS to tamper with any of your methods.
Shrink Resources - Remove unused resources.
Code shrinking is available with ProGuard, which detects and removes unused classes, fields, methods, and attributes from your packaged app, including those from included code libraries (making it a valuable tool for working around the 64k reference limit). ProGuard also optimizes the bytecode, removes unused code instructions, and obfuscates the remaining classes, fields, and methods with short names. The obfuscated code makes your APK difficult to reverse engineer, which is especially valuable when your app uses security-sensitive features, such as licensing verification.
Resource shrinking is available with the Android Plugin for Gradle, which removes unused resources from your packaged app, including unused resources in code libraries. It works in conjunction with code shrinking such that once unused code has been removed, any resources no longer referenced can be safely removed as well.
Cruncher Enabled - After optimizing your png somewhere else, Android Asset Packaging Tool (AAPT) will also optimize by default except you tell it not to. But then the responsibility of optimizing all the PNGs in your images will be left to you.
Multiple APK support is a feature on Google Play that allows you to publish different APKs for your application that are each targeted to different device configurations. Each APK is a complete and independent version of your application, but they share the same application listing on Google Play and must share the same package name and be signed with the same release key. This feature is useful for cases in which your application cannot reach all desired devices with a single APK.
Now to the developers...
Do a demo after talk if there’s time. Inform them that Android Studio 2.2 Preview 3 is downloaded and available for them to collect.
Layout Editor - properties panel, blueprint mode, drag and drop, ui can edit menu features
ConstraintLayout works from the preview mode in xml. Automatically convert your LinearLayouts to ConstraintLayouts
Layout Inspector - takes a screenshot of your current view hierachy and allows you debug it
Firebase Plugin - Firebase has been upgraded to a suite of developer services. Add all the new features of Firebase to your app. They are one click away including analytics, cloud messaging, realtime database, cloud test lab
Enhanced code analysis - More thorough doe inspection with Java8 too
Espresso test recorder - Walk through your app as a normal user and have AS generate Espresso tests for you on the go that you can incorporate into your work. There’s no excuse no to implement UI tests now.
Apk Analyzer: Build, Analyze APK. Lets you see what's actually in your app.
Add C++ support to Android project
You’ll need to download preview 2 separately because a patch could not be issued due to a bug, but that has been fixed in preview 3 and you can install a 20MB patch from Preview 2 to 3 and get to experiment with all the new releases including the automatic espresso testing.