February 23, 2015 Android Lollipop – A Developer’s Perspective The new Android 5.0 Lollipop is one of the most fundamental updates since the introduction of the OS, bringing a ton of performance enhancements. Krasimir Gatev Senior Android Developer, MentorMate A Brave New World The future of Android is here and it is bright indeed! The new Android 5.0 Lollipop is one of the most fundamental updates since the introduction of the OS, bringing a bold new visual style and a ton of performance enhancements. These changes provide new tools, but also lead to new challenges for Android developers. By mastering the components and guidelines of the new OS, developers will be able to create new exciting apps and reinvigorate old ones. Android Runtime (ART) One of the major changes in Android 5.0 is the new ART runtime that replaces Dalvik as the platform default. And what a change that is! The new runtime brings 64-bit CPU support, an entirely new memory allocator, ahead-of-time compilation and improved garbage collection. Users can expect upwards to x3 performance improvement in their applications, as demonstrated by the below graph from Google’s 2014 IO conference. But how does this affect Android developers? Most apps should work just fine without any changes under ART. However, developers should be mindful that they can run into some issues if their app uses Java Native Interface (JNI) to run C/C++ code, or development tools that generate non-standard code, such as some obfuscators. Google has provided some helpful guidelines concerning these cases. Material Design Android 5.0 Lollipop brings one of the biggest visual redesigns the OS has seen to date. Material Design is based on what Google calls “unifying theory of a rationalized space and a system of motion” and it’s goal is to incorporate a consistent visual theme on multiple platforms, including mobile, desktop and wearables. The first step to creating a Material Design app is applying the material theme. To support older versions, a separate styles file will be required. Layouts and components in the application will have to follow specific Material Design Guidelines. These encompass the fundamentals of Material Design and both developers and designers must acquire a firm understanding of them before beginning development. Of course the Material Design look and feel cannot be achieved without some new widgets. These include the new RecyclerView, CardView and more. RecyclerView is a more advanced and more flexible version of one of the most used UI widgets in Android applications – the ListView. The power of the RecyclerView comes from the Layout Manager, which dictates how the items in the list will be ordered. This empowers developers to easily create imaginative and nonlinear item arrangements. Experienced Android developers know how to increase a ListView’s performance by using a pattern called ViewHolder. This pattern consists of a simple class that holds the references to the UI components for each row in the ListView. Now the new RecyclerView fully integrates this pattern and makes it mandatory. CardView is a UI component that shows information inside cards and has a consistent look across the platform. Developers can customize the view’s corners, elevation and more. Another new feature in Material Design is that UI components can now cast shadows. This is achieved by specifying an elevation value for a view, which creates the visual effect of the views floating in a 3D plane, while in fact they are two dimensional. Animating transitions between activities is now even easier with the new Activity Transitions API. Designated shared elements between two views will automatically be animated when the user switches between activities. Power Saving (Project Volta) Project Volta was born from Google’s observation that roughly every 1 second of unnecessary active time (for example the processor waking up to do a task it could do later) results in a 2-minute reduction in stand-by time. In order to remedy this, the company takes an approach it calls ‘lazy first’. Lazy first is basically a principle that encourages developers to schedule non-urgent tasks to be executed in the last possible moment. This can be achieved with the new JobScheduler API that lets developers optimize battery life. by defining jobs for the system to run asynchronously, at a later time or under specified conditions. Such conditions include whenever the device is charging, idle or connected to a network. New tools provide developers with improved ways of monitoring how their app utilizes the device’s battery. A simple way to obtain detailed power usage statistics since the device was last charged for a given app package, is by running the new dumpsys batterystats command: $ adb shell dumpsys batterystats –charged Loading the dumpsys output into Google’s nifty Battery Historian tool will generate an HTML visualization of the data. The statistics including history of battery related events, approximate power use per UID and system component, global device statistics and others. New Notifications With the new Android 5.0 come new and improved notifications. These can now appear on the lockscreen, so users can read them at a glance, without unlocking their phones. Users can manage notification priority and toggle whether they want them to appear on the lockscreen from the Settings menu. Developers now have more control over how their notifications are displayed by setting their visibility property to Private, Public or Secret. Support Library Additions Wide spread adoption of Lollipop is still a ways off, but there are components that developers can use right now in order to bring their old apps up to speed. The new version of the Android Support Library comes with a substantial list of new additions, including the new Toolbar widget, RecyclerView, CardView and others. Developers can start by letting their themes extend Theme.AppCompat which includes everything they need to support Material Design in previous versions. Using a base theme and overriding the final theme in the values-v21 folder is advised in order to retain full functionality for devices running Lollipop. The new Toolbar widget is a generalization of the Action Bar pattern that gives much more control and flexibility. It can be placed as a view in the hierarchy just like any other, making it easier to interleave with the rest of the views, become animated, or react to scroll events. The Toolbar can also be set to represent the Activity’s action bar, meaning that standard options menu actions will be displayed within it. In Conclusion With Android Lollipop Google continues it’s attempts to innovate and grow its mobile platform on multiple fronts. In order to keep up with progress, developers must change the way they think about, design and develop their applications, in order to fascinate users and engage them on multiple levels. Tags MobileCultureDevelopmentSystems Architecture Share Share on Facebook Share on LinkedIn Share on Twitter Share Share on Facebook Share on LinkedIn Share on Twitter Sign up for our monthly newsletter. Sign up for our monthly newsletter.