{"id":6273,"date":"2020-04-15T07:12:22","date_gmt":"2020-04-15T07:12:22","guid":{"rendered":"https:\/\/www.rlogical.com\/?p=6273"},"modified":"2025-03-31T18:45:58","modified_gmt":"2025-03-31T13:15:58","slug":"what-is-android-jetpack-know-about-android-jetpack-components-architecture","status":"publish","type":"post","link":"https:\/\/www.rlogical.com\/blog\/what-is-android-jetpack-know-about-android-jetpack-components-architecture\/","title":{"rendered":"What is Android Jetpack? Know About Android Jetpack Components &amp; Architecture"},"content":{"rendered":"<h2><strong>What is Andoid Jetpack?<\/strong><\/h2>\n<p>Jetpack is a suite of libraries, tools, and guidance to help developers write high-quality apps easier.<\/p>\n<p><strong>Prerequisites<\/strong><\/p>\n<p>To Implement any of the Android Jetpack Components it requires Android Studio version higher than 3.3 and\u00a0 <a href=\"https:\/\/developer.android.com\/jetpack\/androidx\">androidx.*<\/a> setup.<\/p>\n<p>Jetpack comprises the <a href=\"https:\/\/developer.android.com\/jetpack\/androidx\">androidx.*<\/a> package libraries, unbundled from the platform APIs. This means that it offers backward compatibility and \u00a0updated more frequently than the Android platform, making sure you always have access to the latest and greatest versions of the Jetpack components.<\/p>\n<h2><strong>Android Jetpack Components<\/strong><\/h2>\n<h4>&#8211; Foundation<\/h4>\n<h4>&#8211; Architecture<\/h4>\n<h4>&#8211; Behavior<\/h4>\n<h4>&#8211; UI<\/h4>\n<p>&nbsp;<\/p>\n<h2><strong>Android Jetpack Architecture<\/strong><\/h2>\n<h4>&#8211; Navigation<\/h4>\n<h4>&#8211; Live Data<\/h4>\n<p>&nbsp;<\/p>\n<p><strong><u>Getting Started Here:<\/u><\/strong><\/p>\n<p><strong>Gradle Plugins<\/strong><\/p>\n<p>dependencies {<\/p>\n<p>implementation <strong>&#8220;androidx.navigation:navigation-fragment:2.2.0&#8221;<\/strong><\/p>\n<p>implementation <strong>&#8220;androidx.navigation:navigation-ui:2.2.0&#8221;<\/strong><\/p>\n<p>}<\/p>\n<p>apply <strong>plugin<\/strong>: <strong>&#8220;androidx.navigation.safeargs&#8221;<\/strong><\/p>\n<p>buildscript {<\/p>\n<p>repositories {<\/p>\n<p>google()<\/p>\n<p>jcenter()<\/p>\n<p>}<\/p>\n<p>dependencies {<\/p>\n<p>classpath <strong>&#8216;com.android.tools.build:gradle:3.5.3&#8217;<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong>classpath <strong>&#8220;androidx.navigation:navigation-safe-args-gradle-plugin:2.2.0&#8221;<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><em>\/\/ NOTE: Do not place your application dependencies here; they belong<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ in the individual module build.gradle files<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0<\/em>}<\/p>\n<p>}<\/p>\n<h3><strong>Navigation Architecture Component<\/strong><\/h3>\n<p>It simplifies implementing navigation, while also helping you visualize your app&#8217;s navigation flow. The library provides a number of benefits, including:<\/p>\n<p>&#8211;\u00a0 Automatic handling of fragment transactions<\/p>\n<p>&#8211;\u00a0 Correctly handling up and back by default<\/p>\n<p>&#8211;\u00a0 Default behaviors for animations and transitions<\/p>\n<p>&#8211;\u00a0 Deep linking as a first class operation<\/p>\n<p>&#8211;\u00a0 Implementing navigation UI patterns (like navigation drawers and bottom nav) with little additional work<\/p>\n<p>&#8211;\u00a0 Type safety when passing information while navigating<\/p>\n<p>&#8211;\u00a0 Android Studio tooling for visualizing and editing the navigation flow of an app<\/p>\n<p>&nbsp;<\/p>\n<h3><strong>The Navigation Component consists of three key parts :<\/strong><\/h3>\n<p>&#8211; Navigation Graph<\/p>\n<p>&#8211; NavHostFragment (Layout XML view)<\/p>\n<p>&#8211; NavController (Kotlin\/Java object)<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Navigation Graph :<\/strong><\/p>\n<p>This is a resource that contains all navigation-related information in one centralized location. This includes all the places in our app, known as destinations, and possible paths a user could take through the app.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6274 size-full\" src=\"https:\/\/www.rlogical.com\/wp-content\/uploads\/2023\/03\/native-android-app.webp\" alt=\"Navigation Graph \" width=\"1149\" height=\"753\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>NavHostFragment :<\/strong><\/p>\n<p>This is a special widget you add to your layout. It displays different destinations from your Navigation Graph.<\/p>\n<p><strong>Navigation Controller :<\/strong><\/p>\n<p>This is an object that keeps track of the current position within the navigation graph. It orchestrates swapping destination content in the NavHostFragment as you move through a navigation graph.<\/p>\n<p><strong>SafeArgs :<\/strong><\/p>\n<p>With navigation Component you also can pass arguments from one destination to another. For example, a user ID to fetch the details of a user from a remote server or local database. It is recommended to pass only small data between destinations. Like we said a user ID instead of the user itself.<\/p>\n<p><strong>To specify an argument on navigation editor do the following<\/strong><\/p>\n<p>&#8211; Click the Add (+) button on the Arguments panel<\/p>\n<p>&#8211; Then add argument name, type, is it nullable and a default value (if needed)<\/p>\n<p>&#8211; Then select your action and the argument<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6275 size-full\" src=\"https:\/\/www.rlogical.com\/wp-content\/uploads\/2023\/03\/architech.webp\" alt=\"argument on navigation editor\" width=\"1046\" height=\"728\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6276 size-full\" src=\"https:\/\/www.rlogical.com\/wp-content\/uploads\/2023\/03\/code.webp\" alt=\"\" width=\"492\" height=\"290\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>The following example shows you how to use these methods to set an argument and pass it to the navigate() method:<\/strong><\/p>\n<p>Button play_btn = view.findViewById(R.id.<strong><em>play_btn<\/em><\/strong>);<\/p>\n<p>play_btn.setOnClickListener(<strong>new <\/strong>View.OnClickListener() {<\/p>\n<p>@Override<\/p>\n<p><strong>public void <\/strong>onClick(View v) {<\/p>\n<p>Navigation.<em>findNavController<\/em>(view).navigate(R.id.<strong><em>action_title_screen_to_register<\/em><\/strong>);<\/p>\n<p>}<\/p>\n<p>});<\/p>\n<p>In our receiving destination\u2019s code, use the <a href=\"https:\/\/developer.android.com\/reference\/androidx\/fragment\/app\/Fragment#getArguments()\">getArguments()<\/a> method to retrieve the bundle.<\/p>\n<p><strong>Deeplinks<\/strong><\/p>\n<p>With Navigation Component we can use a URI instead of an action to navigate.<\/p>\n<p>Use the <a href=\"https:\/\/developer.android.com\/reference\/androidx\/navigation\/NavDeepLinkBuilder\">NavDeepLinkBuilder<\/a> class to construct a <a href=\"https:\/\/developer.android.com\/reference\/android\/app\/PendingIntent\">PendingIntent<\/a>, as shown in the example below. Note that if the provided context is not an Activity, the constructor uses <a href=\"https:\/\/developer.android.com\/reference\/android\/content\/pm\/PackageManager#getLaunchIntentForPackage(java.lang.String)\">PackageManager.getLaunchIntentForPackage()<\/a> as the default activity to launch, if available.<\/p>\n<p>&nbsp;<\/p>\n<p>With Navigation Component you can use a URI instead of an action to navigate.<\/p>\n<p>PendingIntent pendingIntent = <strong>new <\/strong>NavDeepLinkBuilder(context)<\/p>\n<p>.setGraph(R.navigation.<strong><em>nav_graph<\/em><\/strong>)<\/p>\n<p>.setDestination(R.id.android)<\/p>\n<p>.setArguments(args)<\/p>\n<p>.createPendingIntent();<\/p>\n<p>&nbsp;<\/p>\n<p>We can use the Navigation Editor to create an implicit deep link to a destination as follows:<\/p>\n<p>In the Design tab of the Navigation Editor, select the destination for the deep link.<\/p>\n<p>Click + in the Deep Links section of the Attributes panel.<\/p>\n<p>In the Add Deep Link dialog that appears, enter a URI.<\/p>\n<h3><strong>Note the following:<\/strong><\/h3>\n<p>URIs without a scheme are assumed as either http or https. For example, www.google.com matches both http:\/\/www.google.com and https:\/\/www.google.com.<\/p>\n<p>Placeholders in the form of {placeholder_name} match one or more characters. For example, http:\/\/www.example.com\/users\/{id} matches http:\/\/www.example.com\/users\/4. The Navigation component attempts to parse the placeholder values into appropriate types by matching placeholder names to the defined arguments that are defined for the deep link destination. If no argument with the same name is defined, a default String type is used for the argument value.<\/p>\n<p>We can use the .* wildcard to match 0 or more characters.<\/p>\n<p>(optional) Check Auto Verify to require Google to verify that you are the owner of the URI. For more information, see Verify Android App Links.<\/p>\n<p>Click Add. A link icon\u00a0 appears above the selected destination to indicate that destination has a deep link.<\/p>\n<p>Click the Text tab to toggle to the XML view. A nested &lt;deepLink&gt; element has been added to the destination:<\/p>\n<p>&lt;<strong>deepLink<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0<\/strong><strong>android<\/strong><strong>:id<\/strong><strong>=&#8221;@+id\/deepLink&#8221;<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0<\/strong><strong>app<\/strong><strong>:uri<\/strong><strong>=&#8221;www.example.com\/user\/{userName}&#8221; <\/strong>\/&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6277 size-full\" src=\"https:\/\/www.rlogical.com\/wp-content\/uploads\/2023\/03\/jetpack-live.webp\" alt=\"Android Jetpack Livedata\" width=\"1054\" height=\"709\" \/><\/p>\n<h2><\/h2>\n<h2><strong>Jetpack Live Data<\/strong><\/h2>\n<p>LiveData is introduced as lifecycle-aware data holder with the observer pattern. That means, When something is new in the data set it will notify. It automatically changes the view for the changes in the data set.<\/p>\n<p>In large applications there can be two types of data source. Local Sqlite database, remote Rest APIs . With Live we can write code for observer these data sources for data changes and update views accordingly.<\/p>\n<h3><strong>Benefits of using LiveData :<\/strong><\/h3>\n<p><strong>Ensures our UI matches our data state <\/strong>&#8211; It is based on observer pattern. So we\u2019ll be notified every time the data changes instead of requesting the data each time from ViewModel<\/p>\n<p><strong>Avoid memory leaks <\/strong>\u2013 Observers bounded with life cycle and when lifecycle is destroyed LiveData object also destroy.<\/p>\n<p>No more crashes due to stopped activities- If the observer\u2019s lifecycle is inactive, such as in the case of an activity in the back stack, then it doesn\u2019t receive any LiveData events.<\/p>\n<p><strong>No more manual lifecycle handling<\/strong> \u2013 UI components just observe relevant data and don\u2019t stop or resume observation. LiveData automatically manages all of this since it\u2019s aware of the relevant lifecycle status changes while observing.<\/p>\n<p><strong>Always up to date data <\/strong>\u2013 If a lifecycle becomes inactive, it receives the latest data upon becoming active again. For example, an activity that was in the background receives the latest data right after it returns to the foreground.<\/p>\n<p><strong>Manage all configuration changes<\/strong> \u2013If an activity or fragment is recreated due to a configuration change, like device rotation, it immediately receives the latest available data.<\/p>\n<p><strong>Gradle Plugins<\/strong><\/p>\n<p>dependencies {<\/p>\n<p>implementation <strong>&#8220;android.arch.lifecycle:extensions:1.1.1&#8221;<\/strong><\/p>\n<p>annotationProcessor <strong>&#8220;android.arch.lifecycle:compiler:1.1.1&#8221;<\/strong><\/p>\n<p>}<\/p>\n<h3><span style=\"text-decoration: underline\"><strong>Follow these steps to work with LiveData objects:<\/strong><\/span><\/h3>\n<p>Create an instance of LiveData to hold a certain type of data. This is usually done within your ViewModel class.<\/p>\n<p>Create an Observer object that defines the onChanged() method, which controls what happens when the LiveData object&#8217;s held data changes. You usually create an Observer object in a UI controller, such as an activity or fragment.<\/p>\n<p>Attach the Observer object to the LiveData object using the observe() method. The observe() method takes a LifecycleOwner object. This subscribes the Observer object to the LiveData object so that it is notified of changes.<\/p>\n<p><strong>public class <\/strong>MainViewModel <strong>extends <\/strong>AndroidViewModel {<\/p>\n<p><strong>private <\/strong>WallpapersRepo <strong>movieRepository<\/strong>;<\/p>\n<p><strong>public <\/strong>MainViewModel(@NonNull Application application) {<\/p>\n<p><strong>super<\/strong>(application);<\/p>\n<p><strong>movieRepository <\/strong>= <strong>new <\/strong>WallpapersRepo(application);<\/p>\n<p>}<\/p>\n<p><strong>public <\/strong>LiveData&lt;List&lt;Wallpapers&gt;&gt; getAllBlog(CustomProgressDialog customProgressDialog) {<\/p>\n<p>LiveData&lt;List&lt;Wallpapers&gt;&gt; data = <strong>new <\/strong>LiveData&lt;List&lt;Wallpapers&gt;&gt;() {};<\/p>\n<p>customProgressDialog.show();<\/p>\n<p><strong>return <\/strong><strong>movieRepository<\/strong>.getMutableLiveData(customProgressDialog) == <strong>null <\/strong>? data :<\/p>\n<p><strong>movieRepository<\/strong>.getMutableLiveData(customProgressDialog);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p><strong>Repository for interacting to LiveData<\/strong><\/p>\n<p><strong>public class <\/strong><strong>WallpapersRepo {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0<\/strong><strong>private <\/strong><strong>ArrayList&lt;Wallpapers&gt; <\/strong><strong>movies <\/strong><strong>= <\/strong><strong>new <\/strong><strong>ArrayList&lt;&gt;();<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0<\/strong><strong>private <\/strong><strong>MutableLiveData&lt;List&lt;Wallpapers&gt;&gt; <\/strong><strong>mutableLiveData <\/strong><strong>= <\/strong><strong>new <\/strong><strong>MutableLiveData&lt;&gt;();<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0<\/strong><strong>private <\/strong><strong>Application <\/strong><strong>application<\/strong><strong>;<\/strong><\/p>\n<p><strong>\u00a0<\/strong><strong>public <\/strong><strong>WallpapersRepo(Application application) {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>this<\/strong><strong>.<\/strong><strong>application <\/strong><strong>= application;<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0}<\/strong><\/p>\n<p><strong>public <\/strong><strong>MutableLiveData&lt;List&lt;Wallpapers&gt;&gt; getMutableLiveData(CustomProgressDialog customProgressDialog) {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>final <\/strong><strong>ApiManager apiManager = <\/strong><strong>new <\/strong><strong>ApiManager();<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0apiManager.createService(RestApiInterface.<\/strong><strong>class<\/strong><strong>, <\/strong><strong>null<\/strong><strong>).getWallPaperData().enqueue(<\/strong><strong>new <\/strong><strong>Callback&lt;JsonObject&gt;() {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>@Override<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>public void <\/strong><strong>onResponse(<\/strong><strong>@NonNull <\/strong><strong>Call&lt;JsonObject&gt; call, <\/strong><strong>@NonNull <\/strong><strong>Response&lt;JsonObject&gt; response) {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>try <\/strong><strong>{<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>customProgressDialog<\/strong><strong>.cancel();<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.<em>d<\/em>(<\/strong><strong>&#8220;&#8221;<\/strong><strong>, <\/strong><strong>&#8220;callSearchMember response :: &#8221; <\/strong><strong>+ response);<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>if <\/strong><strong>(response.body() != <\/strong><strong>null<\/strong><strong>) {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0JSONObject jsonObjectResponse = <\/strong><strong>new <\/strong><strong>JSONObject(response.body().toString());<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>apiManager<\/strong><strong>.parseJSONOResponse(jsonObjectResponse);<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0WallPaper mBlogWrapper = parseData(jsonObjectResponse.toString());<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>if <\/strong><strong>(mBlogWrapper != <\/strong><strong>null <\/strong><strong>&amp;&amp; mBlogWrapper.getWallpapers() != <\/strong><strong>null<\/strong><strong>) {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>movies <\/strong><strong>= mBlogWrapper.getWallpapers();<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>mutableLiveData<\/strong><strong>.setValue(<\/strong><strong>movies<\/strong><strong>);<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} <\/strong><strong>catch <\/strong><strong>(JSONException e) {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0e.printStackTrace();<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>@Override<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>public void <\/strong><strong>onFailure(<\/strong><strong>@NonNull <\/strong><strong>Call&lt;JsonObject&gt; call, <\/strong><strong>@NonNull <\/strong><strong>Throwable t) {<\/strong><\/p>\n<p><strong>\u00a0 Log.<em>d<\/em>(<\/strong><strong>&#8220;Failed&#8221;<\/strong><strong>, <\/strong><strong>&#8220;Internal Server error!&#8221;<\/strong><strong>);<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>return <\/strong><strong>mutableLiveData<\/strong><strong>;<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0}<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u00a0\u00a0\u00a0<\/strong><strong>private <\/strong><strong>WallPaper parseData(String response) {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>try <\/strong><strong>{<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Gson gson = <\/strong><strong>new <\/strong><strong>GsonBuilder().create();<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>return <\/strong><strong>gson.fromJson(response, WallPaper.<\/strong><strong>class<\/strong><strong>);<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} <\/strong><strong>catch <\/strong><strong>(Exception e) {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0e.printStackTrace();<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><strong>return null<\/strong><strong>;<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0}<\/strong><\/p>\n<p><strong>}<\/strong><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>Observe LiveData objects<\/strong><\/h3>\n<p>it receives the most recent value from the LiveData objects it\u2019s observing. This only occurs if the LiveData object to be observed has been set.<\/p>\n<p>Generally, LiveData delivers updates only when data changes, and only to active observers. An exception to this behavior is that observers also receive an update when they change from an inactive to an active state. Furthermore, if the observer changes from inactive to active a second time, it only receives an update if the value has changed since the last time it became active.<\/p>\n<p><strong>mainViewModel<\/strong><strong>.getAllBlog(<\/strong><strong>customProgressDialog<\/strong><strong>).observe(getActivity(), blogList -&gt; {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0<\/strong><strong>swipeRefresh<\/strong><strong>.setRefreshing(<\/strong><strong>false<\/strong><strong>);<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0prepareRecyclerView(blogList);<\/strong><\/p>\n<p><strong>});<\/strong><\/p>\n<p>&nbsp;<\/p>\n<h2><strong>Conclusion:<\/strong><\/h2>\n<p>In this blog we explained about Android Jetpack and know about Android Jetpack Components &amp; Architecture. This way Android Jetpack helps <a href=\"https:\/\/www.rlogical.com\/hire-dedicated-developers\/hire-mobile-app-developer\/\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Android app developers<\/strong><\/a> and we should start using it.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Andoid Jetpack? Jetpack is a suite of libraries, tools, and guidance to help developers write high-quality apps easier. Prerequisites To Implement any of the Android Jetpack Components it requires Android Studio version higher than 3.3 and\u00a0 androidx.* setup. Jetpack comprises the androidx.* package libraries, unbundled from the platform APIs. This means that it [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":13815,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[112,38],"tags":[85,161,160,117],"class_list":["post-6273","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android-app-development","category-mobile-app-development","tag-android-app-development","tag-android-app-development-company","tag-android-jetpack","tag-mobile-app-builder"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.rlogical.com\/wp-json\/wp\/v2\/posts\/6273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rlogical.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rlogical.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rlogical.com\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rlogical.com\/wp-json\/wp\/v2\/comments?post=6273"}],"version-history":[{"count":2,"href":"https:\/\/www.rlogical.com\/wp-json\/wp\/v2\/posts\/6273\/revisions"}],"predecessor-version":[{"id":13822,"href":"https:\/\/www.rlogical.com\/wp-json\/wp\/v2\/posts\/6273\/revisions\/13822"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rlogical.com\/wp-json\/wp\/v2\/media\/13815"}],"wp:attachment":[{"href":"https:\/\/www.rlogical.com\/wp-json\/wp\/v2\/media?parent=6273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rlogical.com\/wp-json\/wp\/v2\/categories?post=6273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rlogical.com\/wp-json\/wp\/v2\/tags?post=6273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}