Google I/O 2018: Android Notes

Highlights All android support library code is moving to the androidx namespace. No more android.support.v4 or android. support.v7 namespaces. Android app bundle to split the app into downloadable modules Navigation library to set up navigation between different activities/fragments. Use WorkManager for background work - this is an improvement to JobScheduler Major improvements to Android Studio. Most standalone tools were deprecated in favor of adding the same functionality into Android Studio. Major improvements to Android Vitals which in Google Play to learn more about what’s going on with the Android app’s performance. Android P does more profiling to improve code locality for faster execution. Modern Android Development hierarchy viewer is replaced by ViewTree in Android Studio TraceView is replaced by Systrace in Android Studio Profiler (DDMS) is replaced by Android Profiler in Android Studio Dalvik is replaced by ART Java is replaced by Kotlin as a preferred language Layouts Absolute Layout - deprecated Linear Layout - still OK Frame Layout - still OK Grid Layout - discouraged Relative Layout - discouraged ConstraintLayout - recommended ListView, GridView, and Gallery are deprecated. RecyclerView is recommended with ListAdapter for updations. Platform Fragments (android.app.fragments) are deprecated. Support library fragments are recommended. Single activity app recommended Rather than managing activity lifecycle use Lifecycle to observe state changes Rather than keeping plain data with views, use LiveData to update views automatically. Use ViewModel to deal with screen rotation. Room is recommended in place of SQLite CursorAdapter and AsyncListUtil are discouraged. Use Paging instead with a neat, graceful offline use-case handling trick. Don’t do manual bitmap management. Use Glide, Picasso, or Lottie instead. Between TextureView and SurfaceView, use SurfaceView. Nine patches are discouraged. Use Vector Drawables. Use FusedLocationProviderClient for fetching the device location. Wi-Fi access triangulation is coming to Android P. FusedLocationProvider will eventually add support for that for indoor location tracking. MediaPlayer is discouraged, use ExoPlayer instead. A detailed hands-on presentation on ExoPlayer Performance 42% of 1-star reviews mention crashes/bugs ANR/crash rate reduces engagement - use StrictMode to catch them early Avoid IPC on the main thread, StrictMode won’t catch the violation, and you would never know what’s happening on the other side of the IPC call which can block the main thread If BroadcastReceiver#onReceive is going to take more than 10 seconds, then call goAsync for background processing and call PendingResult#onFinish() once that’s finished WakeLocks - avoid using them. All except PARTIAL_WAKE_LOCK are deprecated with Android P. Use FLAG_KEEP_SCREEN_ON for keeping the screen on in an activity Use WorkManager for background work Use AlarmManager for short-interval callback enums are not discouraged anymore. Platform code avoids it but unlike in prior Android versions, the penalty for enums is low now. A good introduction to Android’s display rendering A good introduction to Android’s text handling Text handling issues Only framework spans can be parceled, don’t mix custom spans with framework spans since only the frameworks will be part of the copied text After ~250 spans or more, SpannableStringBuilder ends up being more performant than SpannableString since the former internally uses trees. Metrics affecting spans cause measure-layout-draw calls, while appearance affecting spans cause layout-draw calls, therefore, the former is more expensive. Text measurement takes a lot of time on the UI thread, consider creating PrecomputedText on the background thread. android:autoLink = true works via RegEx and has bad performance. Consider using Linkify on the background thread. Android P also supports deep learning-based TextClassifier which is also invoked on the background thread. Testing your app for background restriction - adb shell apps set <package name> RUN_ANY_IN_BACKGROUND ignore # applies background restriction (change “ignore” to “allow” to remove restriction) Next Billion Users 28% of searches in India are voice searches 2-wheeler mode added to Google Maps Google Tez uses Ultrasound for pairing and sending money to the nearby receiver Files Go - Folder-based hierarchy won’t work for users who have never had a PC before. Therefore, shows photos based on associations like “WhatsApp Images” or “Camera”. Supports P2P file sharing for fast transfers. Design for next billion users - https://design.google/nbu Android Go 25% of devices in 2018 shipped with <= 1GB RAM (target for Android Go) Every 6 MB app size reduces the installation rate by 1% India - largest market for Go. The USA - is the second-largest market for Go. 5 seconds cold start goal Users opt for smaller apk sizes with a lower rating. The average apk size is 30 MB. Go recommends a 40MB max app size for non-game and 65MB for game apps. MLKit On-device + cloud APIs. On-device APIs are free. Firebase supports downloading models and even doing A/B testing. Experimental support to convert TensorFlow models to TensorFlow Lite models. Compiler D8 - new Dexer, now default. Enable/disable via “android.enableD8 = true/false” R8 - new optimizer, now default replacing proguard, still opt-in in 3.2. Enable via android.enableR8 = true Kotlin - talk can be here Use properties instead of default getters/setters Use data classes to generate equals, hash method, etc. Use default args instead of method overloading Use top-level functions as well as local functions (function inside functions for better encapsulation Use function extensions to make the code more readable, eg. extend String class with isDigit to be able to later write the code like “1234”.isDigit Use smart casts Use sealed classes for a superclass which should not be extendable beyond the compile-time Use string interpolation in println, eg. println(“name is ${name}”) Use val (read-only values) by default, only use var (read-write var iable) when there is a strong reason Declare lambda functions as inline to remove the cost of having an extra class Use co-routines via async instead of creating new threads Use suspend + async to convert callbacks into more readable synchronously written code

Google I/O 2017: Android Notes

Infrastructure - Architecture & Performance Android Vitals - More visibility in Google Play dev console on battery drain, wakelocks being held for too long, ANRs, crashes, dropped frames, and frozen frames. Architecture components - better handling of the lifecycle, Room (ORM for Sqlite), live data observers. The API looks clunky though. Performance 50% 1-star reviews mention stability & bugs. 60% 5-star reviews mention speed, design, or reliability. Apps with > 5% crash rate have 30% higher uninstall rate. Emerging Markets > 100M users came online in 2016. 1B 2G devices expected in 2020. 50% of India is on 2G 33% users run out of storage in India every day. Data is expensive - it costs ~$2 to download a 40MB free app in India 53% users abandon websites if it takes more than 3 seconds to load Action items ...

Apple vs Google: Naming of flagship Android vs iPhone

iPhone iPhone iPhone 3G -> iPhone 3GS iPhone 4 -> iPhone 4S iPhone 5 -> iPhone 5S iPhone 6 -> iPhone 6S (and plus sizes) iPhone 7 (and plus sizes) Android Nexus One Nexus S Galaxy Nexus Nexus 4 Nexus 5 Nexus 6 Nexus 5X & Nexus 6P Pixel & Pixel XL While iPhone is recognized as a global name while erstwhile Nexus and now, Pixel has almost no branding outside of the Android fanboys. ...

Consumer Internet: why audio can't be as big as photos or videos

Our brain loves distractions, and multitasking gets bored quickly. When we read text or watch a photo, it engages us visually, a video (with audio) engages us even more. The bandwidth of eyes is much larger than the bandwidth of our ears. When we are watching something, it utilizes more bandwidth and hence occupies more of our attention span. Also, given the way our eyes work, we can focus more on the exciting aspect of the visual feed. Compared to that, audio underutilizes our brain’s bandwidth. Further, the unidimensional flow of audio data at a linear speed does not mimic our ability to process it. Contrast forced direct listening with how non-linearly humans read. ...

90% vs 99%

Consider two systems: the first is 90% reliable and the second is 99%. The wrong to compare them is to compare the reliability and conclude that the second one is 9% (or 10% if you take 90% as the base) better. The right way to compare them is to compare the unreliability and conclude that the first system fails in 10% of the cases while the second fails only in 1%, making it 10X more error-prone than the second. The reliability comparison is a vanity matrix while the unreliability comparison not only demonstrates the user perception (“The user saw ten crashes in past one hour” vs “The user saw one crash in past one hour”) drastically but also shows the effort that goes into making the system more reliable. ...

When aggregation works and when it doesn't

All consumer internet products are either about consumption, production or both. A blog site is primarily about consumption. A photo transforming app is primarily about production. Social networks are consumption heavy. Good Messaging apps are symmetric. And a grievance collection product like BBB is production heavy. Building aggregation on top of similar products is a well-known strategy. The hard realization to note is that it can succeed only in very specific scenarios. Look at all the successful aggregation products, travel booking sites, news aggregators, RSS readers, discount coupon aggregators. As opposed to that, attempts to write an email aggregator, a social media aggregator etc. have not been as successful. And that’s the underlying theme, aggregator works well for consumption only interfaces where the product is sourced from many sources (more the better) and is standardized in the eyes of the consumer. They have limited success almost everywhere else. And this just doesn’t apply to software products. Microsoft tried and failed to have their own hardware stores since their offerings were similar and a subset of BestBuy whereas Apple succeeded in the same strategy despite the naysayers. ...

The Android-Chrome merger saga

Articles with the following titles would be considered a joke “BMW is planning to merge its series i5 cars and Motorrad bikes” “P&G is planning to merge tissue paper and toilet paper” “Arm and Hammer is working on merging face wash, body soap, shampoo, laundry detergent, and dish cleaner” Not that these combinations can’t be made or have never been made but consumers would just not buy them. They are usually inferior or more convoluted, or even worse, both. ...

Startup valuations

In 2001, Amazon’s share price crashed from 100$ to 6$, they had to do a 15% layoff. But it was Jeff Bezos’s perseverance, tenacity and grit because of which Amazon survived. As several startups from the Bay area to Bangalore get a mark-down of their valuations, the question about how many will survive and eventually produce a [positive] return for their investors is being asked. Between what a startup’s real value is and how viable is its business model, the real question to ask is how committed are the founder(s) to make things works. In the longer run, only that will matter. ...

Voice Interfaces: The Missing User Interaction Element

Apple Siri, Google Now, Amazon Echo, and Microsoft Cortana have garnered a lot of press lately. But one thing which is still missing out is voice-native user experience. Let me illustrate that with the evolution of user experience on touchscreens. When they first came out, there was a stylus, and that’s it. It was an inferior version of the mouse-keyboard-monitor trio. Then some fantastic interactions were invented. Interactions like double tap to zoom, multi-finger rotation, swipe to like/dislike, pull down to refresh, long-press for options, and a Swype keyboard. All of these were native to a touchscreen-based environment. Porting them back to a mouse-keyboard-monitor trio was of limited utility at based and useless at worst.

Google I/O 2016: Android notes

General Multitasking - multi-window mode and picture-in-picture mode. This includes the ability to launch window in adjacent activity, and drag and drop between activities. Notifications - Custom quick settings tile for an activity Multi-locale - users can specify locale beyond their primary locale ScopedDirectoryAccess for the shared storage New file-level encryption mode (as opposed to block-level encryption) and the corresponding Direct Boot Java 8, Jack, and ndk support in Gradle GCC deprecated in favor of Clang TechTalk on Image size/compression PNG - Get image down to 256-bit palette (if possible) or compress them using Zopfli. Test the difference with butteraugli Convert PNG to Vector drawable using Potrace. Vector drawable are natively supported on Android 5.0 and above. Use compat to use them on the older versions. Or generate PNG for the older versions (not recommended) WebP is another option (Note: Speaker failed to mention that WebP is natively supported only on Android). Avoid JPEGs. They are usually larger in size.