Category Archives: Jetpack

Jetpack is a suite of libraries, tools, and guidance to help developers write high-quality apps easier. These components help you follow best practices, free you from writing boilerplate code, and simplify complex tasks, so you can focus on the code you care about.

Jetpack comprises the androidx.* package libraries, unbundled from the platform APIs. This means that it offers backward compatibility and is updated more frequently than the Android platform, making sure you always have access to the latest and greatest versions of the Jetpack components.

Room basics – ViewModel

In this chapter of the Room basics tutorial we are going to talk about how we can use the Room queries through a ViewModel. It means, we are going to call the queries from the ViewModel to follow the MVVM design pattern.

We can use the ViewModel as a communicator between the user interface and the repository. It holds the data in a lifecylce-conscious way, which survives configuration changes.

 

Continue reading Room basics – ViewModel

Follow and like us:

Room basics – DAO, Database and Entity

In this chapter of the Room basics tutorial, we are going to talk about the main part of Room, which is the creation of the DAO, the Database and the Entity.

In short

      • DAO stands for Data Access Object, which is an interface, that contains the queries to access the database. It is annotated with @DAO
      • Database represents the database. Because it holds a connection to the SQLite database, all operations are executed through it. It is annotated with @Database.
      • Entity represents a table in the Room database, which should be annotatad with the @Entity keyword.

Continue reading Room basics – DAO, Database and Entity

Follow and like us:

Room basics – The starter project

In this chapter of the Room basics tutorial we are going to create the starter project. It means, that we are going to add the needed dependencies, add the fragments, implement the RecyclerView, which will hold our todos, create the data class and finally we will create the navigation graph as well.

Because we will use in this tutorial Kotlin Coroutines, Navigaion– and Lifecycle components, we have to add to the project some other dependencies. Thenafter we can start to implement the RecyclerView for our todos.

So, let’s start coding! 😎

Continue reading Room basics – The starter project

Follow and like us:

Room basics – Introduction

In this tutorial we are going to talk about how we can implement in our Android applications the Room persistent library. For this, we gonna create a whole new app. So, you can have a big picture about this library. In the introduction part we are going to summarize the tutorial.

Previously, if we wanted to store data locally on an Android device, we had to create manually the database helpers and the SQL queries. It took a long time and it wasn’t an easy task, because we could make many errors also, what what we got only at runtime.

Then Room come to the rescue. It was released in the Google I/O 2016. Room is one of Google’s architecture component library for working with SQLite on Android.

With the release of Version 2.1, the library added support for database transactions using coroutines.

Continue reading Room basics – Introduction

Follow and like us:

Guessing Game – Play the game

In this chapter of the Guessing Game tutorial we are going to implement the core part, which is how we can play the game. For this, we are going to create one more ViewModel. This ViewModel will contain the business logic about the game.

In the very last chapter (Guessing Game – ViewModel), we have implement a ViewModel class already, which is responsible to change the username, and store it indside of a LiveData.

First, we are going to create an enum. This enum will hold the 4 states of the game. Then, we gonna start the implementation of the GameViewModel, which will contain the business logic. It means, here we gonna generate the random numbe to guess, then compare this number to the number of the guess, show the result and start a new game. Inside of this ViewModel we gonna implement two more methods, which will help us to show and hide the soft keyboard after every guess.

So, let’s start coding! 😎

Continue reading Guessing Game – Play the game

Follow and like us:

Guessing Game – ViewModel

In this chapter of the Guessing Game tutorial we are going to implement the first ViewModel, which will be a helper to change in real time the username.

In the very last chapter we have implemented the Navigation Component. This Jetpack library is responsible for the navigation inside of the app.

In our case, we have implemented 2 destinations. The first is the GameFragment, the second is the bottom sheet dialog. We can open it by tapping on the TextView of the username, or by clicking on the pen icon. After that, we can write our username inside of the EditText, but still it won’t be changed in the app.

We are going to implement this functionality by using a ViewModel and a LiveData. This LiveData will hold the username, what we will bind to the TextView inside of the GameFragment using Data Binding with layout variables and layout expressions.

So, let’s start coding. 😎

Continue reading Guessing Game – ViewModel

Follow and like us: