Last week we started the Android Workshop at Poatek, that will happen every Monday from now on: our goal is to build, together, an app that will use the best practices and resources to develop Android applications. I believe that there is always more to be learned, and for this reason, I think the Workshop will be a great opportunity for us to share knowledge.
During the Workshop we intend to practice:
We always use records to keep information about application events. For example, I confess that I love to keep records about the messages between server and client. I recommend using Timber as the logger, because this library is very simple, and has good resources (if you use Logcat, please try it!).
We intend to use different thread abstractions provided by the Android Platform. A common case is when you need to create a Splash Screen with some loading progress. The first thing that comes to my mind is to create a thread timer. Do you write a new thread timer? No, you need to look for a library provided by Android to solve that (e.g. CountDownTimer).
A great and super important topic in any application is the list component. I think 90% (or more) of Android applications have lists, and the developer needs to know how to create a list and manage its elements. Before, the component used for listings was the ListView and, depending on the layout, it was possible to create a few things with the GridView and so on. When RecyclerView came up, it opened several opportunities, such as the possibility of changing the LayoutManager according to the type of visualization you want (linear, grid, etc), and most importantly, the recycling of elements. RecyclerView makes it possible to update only the elements seen by the user. Sometimes, we have a list with hundreds of cells, with a complex layout, where updating is costly. Can you imagine updating only the range seen by the user? notifyItemRangeChanged from our friend Adapter.
There are many features in the data persistence part, if you need to store simple information about user preferences. Let’s say they want the sound enabled in a game, a boolean value. In this scenario, due to the simple nature of the information, it is indicated to use SharedPreferences from the Android library, a kind of HashMap where you specify the key and the value for a certain preference. If the information to be persisted is more complex, with the need for a database, we have to use SQLite. In this case, Room, the Object Relation Management persistence library in the Android platform, would be a good option.
The ViewModel and data binding are features that help the developer implement the MVVM architecture. With ViewModel, the responsibility of maintaining the data can be left completely to it. And data binding allows you to specify behaviors in the layout according to the changes in the ViewModel. These two features make it possible to construct a more consistent application and increase the cohesion of the system (data and graphical interface).
Fragments are extremely important. Many times, we want to build a screen component that will be used by various activities — this is possible through fragments. We can also define contracts, so that a fragment can respond with actions to the components that use it.
In Android, there are a lot of cool libraries, but which one to use? A good tip is to access the Android Arsenal to see what is indicated by the community link.
Firebase is very powerful, from analytics to crashlytics and other resources.
If you like to do regression tests to verify that the graphical interface of the application is behaving as expected, a good tip is Espresso, which allows you to specify actions to be performed in the app in order to simulate the behavior of the screens.
Dependency management is very important in any kind of software development. For example, in Android, knowing how to use Gradle is a necessity. It’s a great help when we need to add a dependency in the project, create a task to perform a custom build, and so on.
Surfaces are very well-used. Sometimes the idea is to make a surplus on a certain element, or to make an elevation visual effect, the possibilities are varied with the use of surfaces.
ConstraintLayout allows you to make adaptive layouts according to the size of the component.
Another cool concept to mention here is the Adaptive Layout. It is visible when the application adapts the screen elements according to the resolution of the device. To do so, it is necessary to create layout variations for each orientation, device size, and so on. When the app runs, the Android System will change the best layout according to the device in runtime.
It was just an overview!
Here are some interesting links I recommend:
About the author
Gabriel Bronzatti Moro is a Mobile Software Engineer at Poatek. He has a master degree in Computer Science at the Federal University of Rio Grande do Sul. Also, he has a degree in Software Engineering at the Federal University of Pampa. He likes software development, gaucho culture and music. He loves guinea pigs.