Skip to main content

Posts

Showing posts with the label LiveData

Architecture Components: Paging Library With Room Database

Paging Library is one of the main parts of the complete set of the Architecture Components Library for MVC app development.  Architecture Components Library includes ViewModel , LiveData , RoomDatabase and Paging Library. In this article, we will create a TODO app that loads the paged data from Database. Architecture Components Paging Library Paging Library includes the DataSource , PagedList , PageListBuilder and PagedListAdapter . We will go through each component one by one. But first of all, What is paging Library? Paging Library is a set of the component which helps app developer to load the data from backed gradually as it required. For example, an app loads thousands of line from the database or network but that all data can’t be display at once to the user. Just a small portion of all those data will be displayed to the user at a time. But if the app goes to load all these data at once then it creates the huge burden on the network and slows down the app as well. If we load ...

WP Android App using REST and Volley with LiveData and ViewModel Part3

In last two part of our WP Android App using REST volley tutorial we have learned about how to fetch the post using REST api from wordpress website. In this part of the article we are going to implement the ViewModel and LiveData component to avoid the refresh every time when any configuration change happening in your app. When configuration change happen in any android application. A common event which trigger the configuration change is the screen rotation. So whenever any configuration change event happen then application will fetch the details from server. Which is creating unnecessary call to backend server and network. Solution of the Configuration Change Data reset issue As explained  above whenever any configuration change happen data is getting reset and application try to fetch the details from the server. As solution of this problem we are going to implement the ViewModel and LiveData architecture component to our application. First of all we are explaining here what we al...

Using Room Persistence Library for SQLite Database

This article is all about Using Room Persistence Library Android Architecture Components for SQLite Database management on Android device. Room is a Persistence Library which provides an abstract layer over SQLite Database. Using Room we utilize the full power of SQLite database without any compromisation with performance. Even it provides several benefits over using the SQLite database with API and plain SQL query. Why should we use the Room for SQLite Database Room provides a persistence layer over SQLite database.  We should use the Room for creating the cache for our application so that we can access the app future even if your app is offline. When the user comes online then data can be sync online over the internet and give the user a seamless user experience. Benefit of using Room Persistence library Your App One of the major benefits of the Room Persistence library is that it provides compile-time SQL validation. So there is no chance of runtime SQL exception as validation d...

How to use LiveData and ViewModel as Async Task Loader

We often required to load some data which take a long time to load. For this, we use the Async Task Loader to load the data in the background. But now we have an alternative for this work and we can use the LiveData and ViewModel as Async Task Loader. In this article, I am going to explain how to use the LiveData and ViewModel as Async Task Loader. LiveData and ViewModel as Async Task Loader Here to explain the use of LiveData and ViewModel to load the data like Async Task Loader we will create an app to list all installed package on a device. Below is the sample of the app which we are going to develop in this article of How to use LiveData and ViewModel as Async Task Loader. In this Article, I am going to create a demo app to list all app installed on your device. We will create four class and will go with each of the class one by one. AppData.java: It is the POJO to store the details of the apps like AppName, Package Name, Icon. AppDataModel.java: It is the main class in which we w...

Lifecycle Aware Data and Configuration change handling with LiveData

LiveData is a data holder class of Google latest Architectural Component which can be observed and in case of any change in the data, it will notify the bound activity or fragment about the change. So what is the difference between normal observer and LiveData observer? and the answer to this question is that Livedata observer is the lifecycle aware class. What does mean if we say Lifecycle aware class? As you know any activity and fragment goes through several states, like an activity is created, started, paused, destroyed and resumed. So normal observer doesn't know about these state of the activity and fragment but Livedata knows. That's why we say LiveData is the lifecycle aware class. The benefit Lifecycle aware class like Livedata? The main benefit of Lifecycle aware class is that you don't have to worry lifecycle of bound activity and fragment changed. So we don't need to update the UI manually instead of that we can create the observer to update the UI with the ...