Image created from ADS 2019 Logo

What’s New in Android #2 : A ton of updates

Harun Wangereka
9 min readOct 28, 2019

--

Android Dev Summit is over and there is a couple of updates to catch up with. I must say that there were key updates in almost all key areas of Android Development.

In this article, I will highlight some of the key updates both technical and non-technical that were announced at the summit.

For those who have not yet caught up with what’s new at Google I/O Earlier on, here is my first article of the series What’s New In Android

From the summit, I can say that we are heading to better times for Android Development. The future is indeed bright.

Take aways from the Keynote

The keynote was done by Dave Burke and he had this to say about areas that will be key in Android Development in the Next 10 years :

  1. Helpful Innovation. Building features that will help users feel empowered for example the Android emergency location services
  2. Updatability — making sure users get updates quickly as demonstrated by Project Treble, which separated software and hardware updates
  3. Security — keeping users safe
  4. Privacy — protecting users data
  5. Great Developer Experience — with the Great Developer Experience, we now have Modern Android Development as a thing.

Modern Android Development is driven by the following key things :

  1. Openness
  2. Designed for scale
  3. Opinionated
  4. Powerful
  5. Safe
  6. Developer -centric

We can see this by the efforts in Jetpack Compose , Kotlin, Jetpack libraries and tooling support. It has seen an increase in the apps that use Kotlin on Google Play, that is 60% of top 1000 apps and we have 53 % of pro Android developers using Kotlin.

So that was just the highlight of the key things from the keynote. Now on to the exciting part of the article where we look at some of the technical announcements and updates that were made .

Take aways from the technical stuff

Android Studio and Android Studio Design Tools

This is probable the most exciting announcement at the Summit. Android Studio 4.0 Canary 1 was released and it comes with a couple of new and amazing additions like :

  1. Embedded emulator — see the emulator running side by side in Android Studio .
  2. New Motion layout editor — makes it easier to create animations and also play the animations in Android Studio
  3. Custom layout preview — you can now visually see custom views on the layout editor.
  4. Layout inspector — live layout inspector and changes made to attributes are instantly reflected in the editor. Has a declared attributes section where you can see resources to the views like color, strings etc. and shows where the resources come from. You can also drag it to view in 3D the view the whole layout stack. This also shows even textures that are hidden.
  5. Multiple Displays — you can now view multiple displays with the emulator with different screen sizes and settings.
  6. Multi Preview — you can visualize different layout configurations on the layout editor.
  7. Better Location support for emulator — with the emulator, you can save routes and when you open the app, it will be able to show motion on your saved route.
  8. Resource manager — updated clip arts and vector assets. Also we have the support for the different type of material icons like filled, round, outlined sharp and two tone.
  9. Build speed profiler /Attribution— Gives a breakdown of what actually happens during the build . It also gives a breakdown of build time for each plugin . It also highlights task setup issues. It shows non — cache-able tasks and incremental annotation processor tasks
  10. Kotlin Gradle DSL —you can now write your build files in Kotlin. Has code completions and lint checks.
  11. Libraries desugaring in D8 and R8— enables you to access API’s that normally require higher API levels on lower API levels.
  12. Improved support for proguard files — Better code completion, go to declarations and better refactoring support.
  13. Dynamic Features — we have feature-to- feature dependencies now. A feature can depend on another feature.
  14. Layout editor improvements — we now have device rendering libraries in IDE. This enables reactive performance, improving text justification mode,detailed shadows 3D perspective and text path rendering.
  15. New Fragment wizards and fragment templates.
  16. Chrome OS Android App Development — you can now deploys apps directly to chrome OS, with no need to use developer mode with the Chrome OS M80 Release.
  17. Jetpack Compose Preview — We have the @Preview(“component name”) annotation, you can now see previews for Jetpack compose components in Android Studio. Previews can be more than one and can be in dark mode too. Compose will also see a better tooling support in Android Studio
Photo from Android Developers Twitter account

Room 2.2

Room 2.2 comes with a couple of updates. This release sees the support for Flow being introduced. @Query DAO methods can now be of return type Flow<T>. The returned Flow will re-emit a new set of values if the observing tables in the query are invalidated.

This version sees the introduction of pre-packaged databases. There are two new APIs for creating RoomDatabase from an already populated database file. We have createFromFile() for creating database from a file in an arbitrary location. We also have createFromAsset() if the pre — populated database is in the assets folder . Here is how the builder will be like :

Room.databaseBuilder(appContext, TestDatabase.class, “Sample.db”)
.createFromFile(File(“mypath”))
.build()

And for creating from asset where the database is in assets/myapp.db

Room.databaseBuilder(appContext, TestDatabase.class, “Sample.db”)
.createFromAsset(“myapp.db”)
.build()

We have introduction of schema default values, not the Kotlin one though.@ColumnInfo now has a new property defaultValue that can be used to specify the default value of a column.

This versions also sees better support for relations in Room. With the @Relation room can now support one to one,one to many and many to many relations.

Room is now a Gradle isolating annotation processor and incrementability can be enabled via the processor option room.incremental. You need to add the following code in your app build.gradle level

A new experimental compiler option room.expandProjection was also added that causes Room to rewrite a query with a star projection to only contain the columns in the returning type POJO . To set it up in gradle :

For example you have a List<Song> and the song data class has the following fields

Before 2.2, if you are only interested with the list with the id and songName only you had to have all the other fields which you are not interested in, but now with 2.2 you can do this :

Now room will re-write our query to retrieve id and songName from song table .

Another feature is that the DAO annotations @Insert, @Update and @Delete now has a new property targetEntity, that allows specifying the target table the DAO method is meant to act on. With our above example where we have the data class NameAndId we can have a method in the DAO class that users that to insert to the song table as follows:

This allows us to pass the different POJO class instances having the same columns of an entity class.

Jetpack Compose

Compose is a modern, declarative UI toolkit. It was first announced at Google I/O 19 and at the summit, the developer preview was released, which works with the latest canary version of Android Studio 4.0.

There is also a tutorial for jetpack compose. Get the tutorial here

Jetpack aims at simplifying creating User Interfaces in Android . Here is a sample from the What’s New in Jetpack compose talks that shows how simple it is to filter a list of items in compose

No more cheating in Jetpack compose. No more relying on private APIs anymore. No more using @Hide annotation for hiding implementation details of API’s.

Compose will also plugin to existing components very easily for example the material components. It also offers compatibility with exiting views.

Composable functions are the building blocks for Jetpack compose. They are functions that describe the UI. They take inputs and decide which UI to display based on the inputs. To create a composable function, you use the @Composable annotation.

We have the following layouts for compose:

  1. Column — vertical linear layout
  2. Row — horizontal layout
  3. Flex — its a new layout
  4. They are also working on having constraint layout

We also have Draw and Layout for building custom views in compose

What’s cooking in the minds on the Compose team : Some of these are not yet implemented!

  1. Data flow — away of state management over time. Observability is required and compose adds @Model classes to help in this and also allows cross-cutting observability.
  2. Resources — a way to avoid too many overloads. There is also the thought of introduction of coroutines in compose and layering which is a pretty good idea
  3. View Compatibility — compatibility with the existing views

Google Play Updates

We had a couple of new features announced which are :

  1. Internal app sharing — has been there for a while but is worth the mention. It allows you to quickly share debug and release builds of your application with others. You can generate the link for the app and share it with a group of testers or make it that anyone with the link can download your app. No more uploading apks to google drive or any other place for sharing!
  2. Install old versions of your app via a link — Users can now install older versions of your application via link which will be available in Google Play Console.
  3. Test dynamic delivery offline

Gesture Navigation

Majority of Android 10 devices will be shipping with the new gesture navigation. This means that we will be having two navigation modes:

  1. 3 button mode will be available on all devices
  2. Gesture navigation mode is optionally available and can be used as default.

Why learning about gestures is important :

  1. To Avoid conflicts with gestures for optimal UX
  2. To gain an edge on user experience given market desire for beautiful UI

To know more on going edge to edge you can read this article by Chris Banes which explains everything that you need to know about gesture navigation .

Work Manager

For work manager, there was no specific updates but in case you have used work manager and wondering why your work is not running, here are some reasons:

  1. Unsatisfied constraints — Constrains specified in your work request not being met.
  2. Doze mode — kills all background processes to preserve battery and this might also cancel your work.
  3. Battery saver mode — kills all processes in order to preserve power
  4. Overall system is overworked
  5. Failed or incomplete pre-requisites
  6. App is force-stopped

Fragments

Fragments have really come a long way. And we had a couple of new additions where androidx.fragment 1.2.0 was released. Focus is mostly on building predictable APIs which are backward compatible.

FragmentContainerView is a new view that will be used for hosting fragments and replaces FrameLayout

We also have FragmentFactory which is a new way to customize how Fragments are created.

androidx.fragment:fragment-testing also is getting updates to allow you provide factories to build the fragment under test. This means that you can have a mock factory which will use constructor injection to inject mock dependencies in the fragment .

Future Plans for the team working on the Fragment API’s are:

  1. Mutliple Backstacks
  2. Common OnActivityResult for both Fragments and Activities
  3. Merging lifecycles for both fragments and views.

As I was preparing the #02 series of What’s New In Android, the idea of making this a series came in to my mind, so every 2–3 months, I will be having the What’s New In Android Series to cover most of the new releases in Android and also jetpack libraries instead of having to do it after every big event, it will be more regular. A GitHub repository of the same will also be coming.

See you in What’s New in Android #03!

Suggestions and improvements are very much welcome!

--

--

Harun Wangereka
Harun Wangereka

Written by Harun Wangereka

Google Developer Expert for Android | Android Engineer | Co-organizer droidconKE, Android254 & Kotlin Kenya | Android Author @raywenderlich.com

No responses yet