Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Android Development: Droidcon Ideas to Get Inspired By

DZone's Guide to

Android Development: Droidcon Ideas to Get Inspired By

Check out all the Android talks and presentations at the recent droidcon in Berlin, and see some of the newest innovations.

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

One of your top priorities if you’re a mobile dev is staying up to date and remaining inspired by new things, even if it means challenging your beliefs. Luckily, that’s what good conferences are for. And that’s why me and Maciej headed to Berlin. The droidcon conference series doesn’t need to be introduced to anyone who’s really into Android development. Read on – for a controversial take on React Native, why Kotlin is a new standard, and why we ran into Star Wars characters.

Droidcon, Google, and Room

We went straight to Florina Muntenescu’s session “Data persistence in Android: There’s room for improvement.” Florina works for Google, and I’ve known her from several blog entries. She talked about a new library released by Google called Room. It’s an abstract layer over SQLite that dramatically simplifies query creation. Its possibilities are amazing and oriented towards the observer pattern. Now, it’s easier to write a query using annotations.

In Room, there are 3 types of components:

Database – to create a database holder:

@Database(entities = {Address.class}, version = 3)
public abstract class AppDatabase extends RoomDatabase {
    public abstract AddressDao addressDao();
}

Entity – represents class and one row in a database:

@Entity
public class Address {
    @PrimaryKey
    private int id;

    @ColumnInfo(name = "street")
    private String street;

    @ColumnInfo(name = "city")
    private String city;

    // ... Getters and setters
}

DAO – component represents an interface as a Data Access Object (DAO). The main component for defining methods which access the database:

@Dao
public interface AddressDao {
    @Query("SELECT * FROM address")
    List<Address> getAll();

    @Query("SELECT * FROM address WHERE id IN (:addressIds)")
    List<Address> loadAllByIds(int[] addressIds);

    @Query("SELECT * FROM address WHERE city LIKE :city AND "
           + "street LIKE :street LIMIT 1")
    Address findByCityAndStreet(String city, String street);

    @Insert
    void insert(Address address);

    @Delete
    void delete(Address address);
}


Room also integrates with RxJava and the new Live Data. The library is still in the alpha phase so applying it to a production code can be a bit risky. We’re looking forward to the stable version. Florina’s presentation was very thoughtful and clear.

Hello Kotlin

Then, we attended “Starting from scratch in 2017,” led by two guys from HERE Technologies. Stefano and Simon talked about what changed in Android architecture this year. The guys encouraged to switch to Kotlin because such transition comes at zero cost: Kotlin syntax is simple and easy to learn and Android studio has built-in converters from Java to Kotlin. They encouraged to use the MVVM (Model-View-View-Model) design pattern. This is the start of another era in Android development, or, more precisely, the development of Android application architecture. At Espeo we still use MVP (Model-View-Presenter) but it’s high time to make the switch to MVVM.

Stefano and Simon compared two new API alternatives: gRPC and GraphQL. All of them generate client-side platform-specific code automatically. There could be a license problem with GraphQL  because it has Facebook-patented features. So, gRPC has the best performance, but GraphQL provides a better organized interface to the data.

They then described persistence and cache layers, and compared libraries such as Room, DbFlow, Paper, and Realm. They encouraged the use of the Repository pattern. I liked it when they showed a cool approach to treating CI (Continuous Integration) like you’d treat code. Use the Jenkins Job DSL configuration files, save it in the repo, do a code review of a new configuration and test it. On the slide below they described how they think the code writing process should look like. Every code change should go through code review and should be checked by automated testing.

Image title

More Android Development Tips

I also went to Garima Jain’s presentation Dagger 2 Android: Defeat The Dahaka. She described the advanced use of Dagger 2 for dependency injection. Without DI, you can no longer imagine today’s applications and tests.

Xavier F. Gouchet, Android Architect at Deezer, talked about Android tests in his presentation Genetically modified tests. He presented an interesting plugin that’s used for mutation tests: gradle-pitest-plugin.

Later on we went to the presentation of Danny Preussler The Power of Kotlin For your Tests. He encouraged us to write tests in Kotlin even when the production code is written in Java. He recommended some nice libraries: the Kluent, or “Fluent Assertions,” library written specifically for Kotlin and Kotlin Mockito.

His presentation took the form of live-coding. Danny doesn’t hide the fact that he’s fascinated by Kotlin:

Image title

Is React Native Worth It?

One of our customers was recently wondering whether to write a mobile application in React Native. To me, the answer to this question was in Andy Dyer’s presentation: React Native: Is it worth it. He described in detail how he ran his process and what sort of problems he encountered. Unfortunately, it seems that JavaScript, although very universal, has not turned out to be the perfect solution or the golden mean.

In spite of its immense popularity, React Native isn’t ideal for modern Android development. It has its good points (we’ve written about that too). However, it’s not great for sophisticated applications with complex architecture. It uses an old version of OkHttp, and as it’s the brainchild of the folks at Facebook, it uses a license that’s not fully open source. The final conclusions were not very optimistic:

Image title

On the next day, we got a great presentation from Hendrik Kokocinski – Brave new world!? Exploring app design with architecture components and Kotlin. He talked about the next steps on the way to better Android development. The final step was the transition to Kotlin and MVVM architecture. He talked about Live Data and Room using a lot of interesting code.

If you are interested in a great ORM, then I recommend Room and Objectbox: New persistence solutions by Markus Junginger. The Greenrobot boys created a new free library called Objectbox, which reached stable version 1.0 on the day of the conference. They focused on performance, they even used C ++ to improve performance and the results look impressive:

Image title

Pre-Conference Afterword: Teslas and ‘Droids

This edition was located in the trade fair part of the city, to be more precise, in CityCube. By chance, the venue also hosted IFA trade show, which we visited before droidcon. So on a sidenote, IFA was also impressive. The latest innovations in electronics were presented in an area the size of 20 football fields. We were mostly looking for cool new mobile-based stuff. Some expos were breathtaking. Couldn’t resist taking some pics. Just look at LG’s exhibit tunnel:

Image title

There were also stars from Star Wars. Though it'd be better to see them ‘droids, if you get me...

Image title

We also took a peek at the exhibition of electric cars. I don’t know if you know, but Tesla has their own application as well as an unofficial API that lets you write your own Android applications and control various car functions. From what I know, you can’t control the ride itself – that would be too dangerous.

Image title

It’s a Wrap…

In conclusion, droidcon conference and Berlin – a perfect match, with so much to get your gears going. Looking at the industry, you can come to the conclusion that Kotlin is already a standard – and, perhaps, Java’s becoming passe? Similarly, MVP is being displaced by MVVM. If you’re into Android development, there’s a droidcon in Poland in December. Remember to leave a comment if there’s any Android development question that’s burning in your brain right now, because we’re all super-inspired and ready for some discussion.

Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

Topics:
mobile ,droidcon ,android

Published at DZone with permission of Marcin Latos, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}