Skip to main content

Posts

Showing posts from August, 2022

Coroutine- A complete tutorial

 What are coroutines? To know about coroutine, first you need to know about asynchronous programming, thread and multithreading concept. What is a thread? Thread describes in which context the function or sequence of instructions should be executed. So, every block of code or functions runs in a thread, right? Also, you can load multiple threads to perform different block of codes  How to start a thread? Thread thread = new Thread(){     public void run(){       System.out.println("This is a thread");     }   }     thread.start(); So when coming to android, before learning about coroutines we need to discuss some scenarios. Normally how an app works when user launch an application. When user launchers the application, a main thread is created. This thread is intended to do small operations like button clicks, UI interaction , small mathematical operations. We cant perform long running operation like file download, database queries, network operations and image

How to get the device information programmatically in android

You can use Build class to get the information of the device and the operating system details in which your app is running        val manufacturer = Build.MANUFACTURER val model = Build.MODEL val version = Build.VERSION.SDK_INT val versionRelease = Build.VERSION.RELEASE   Log.d( "Device Information", """manufacturer $manufacturer model $model version $version versionRelease $versionRelease""" )  

Live Data. Difference between livedata and mutable live data. Mediator Live Data. Live Data Encapsulation

What is Live Data?   Live Data is one of the first architectural components. Live Data is a data holder class. Not only a simple data holder class, but having lot of features. We can say that it is a simple, lifecycle aware, observable, data holder class. Before introducing live data , we need to manually handle the updates in the UI. We were using traditional approaches like interfaces, events buses to update the UI. These traditional approaches having problem like manual handling of lifecycle, memory leaks, and crashes.  Live Data It is wrapper which can be used with any data such as data and objects that implements collections like list. A Live Data usually declared and used inside a view model class. Live Data can be used to observe the change of a particular data and update the UI based on that. Due to life cycle aware property we don't need to bother about components life cycle. i.e. it will send the update only when the component (activity/fragment)  is in active state. If t