Skip to main content

Posts

Showing posts from January, 2018

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

How to use View Model Architecture Components to preserve the data of the Activity and Fragment

In this tutorial, we will learn how to implement the View Model Architecture Components to preserve the data of the Activity and Fragment.  You know, Activity or Fragment is get created and destroyed very frequently whenever any configuration change has at the Android system level.  For example whenever you rotate the screen activity and fragment will go through the full lifecycle and it gets recreated again. In this scenario, all data of your UI element will get lost. So ViewModel is the solution to this problem. Introduction To clear the concept of View Model and implementation of it, we are making this tutorial very simple. In this, we will add two component a TextView and Button at layout layer. When the user clicks on the Button TextView will show the number of clicks. What happens in this case at the screen rotation TextView click count get reset.  As the solution of this, we will implement the ViewModel so that number of click count stored into the variable of main activity shou

Scan WiFi Network and Connect Example Android

In the last tutorial of WiFi network, we have learned about how to get available wifi networks and display them in a list in android. Here, In this part of the tutorial, we will learn about how to connect to specific SSID when the user selects the available wifi networks. In this article, we have to use code from the earlier article about how to get available wifi networks and list as the base app. So if you don't go through the last tutorial you can check out it Scan and List all WiFi In Android. Overview of the Project First of all, we would like to give you the basic idea about the project work that we need to do to accomplish this Demo App. Setup the click even on WiFi View from Adapter Set the OnClickListener to adapter Show Popup to user for Password Input of the Network Get the type of security used by the Network Connect to selected WiFi Network Setup the click even on WiFi View from Adapter So for adding the adding the click event to our WiFi view, we