Posts

Exploring Android Slices - JetPack

Image
Introduction: Slices are a new way of embedding our app's content in other surfaces, like Google Search and later in other places like Google Assistant. Slices are UI templates, which gives look and feel at home in whatever surface, they get hosts in. Also they are rich, interactive and dynamically updatable. Before jumping into that, first migrate your project to AndroidX, (Android Studio 3.2 & above), by navigating as,                                         Refactor --> Migrate  to AndroidX  Setup: build.gradle implementation 'androidx.slice:slice-core:1.0.0' implementation 'androidx.slice:slice-builders-ktx:1.0.0-alpha6' implementation 'androidx.slice:slice-builders:1.0.0' Creating Slice Provider: Slice Provider is a component that let us display the slices we are creating, on outside our application. We can create the Slice Pro...

Using RxJava, Retrofit in Android - Kotlin

Image
Introduction: Reactive Programming is a programming paradigm that’s concerned with data streams and propagation of change. The reactive model listens to changes in the event and runs the relevant code accordingly. RxJava is a Java based implementation of Reactive Programming. Whereas, RxAndroid is specific to Android platform which utilises some classes on top of the RxJava library. Classes and Concepts: There are 3 main components in RxJava. (i) Observable - It emits a stream of data or events. i.e., a class that can be used to perform some action, and publish the result. (ii) Observer - It receivers the events or data and acts upon it. i.e. a class that waits and watches the Observable, and reacts whenever the Observable publishes results. It have 4 interface methods to know the different states of Observable, as follows:         onSubscribe() - invoked when the Observer is subscribed.         onNext() - invoked when t...

Databinding in RecyclerView - Android - Kotlin

Image
Hey Guyss!! Already we have seen the basics of Databinding and how to use it in previous  post . Now let's see how to use Databinding in RecyclerView . And Its gonna be a short post. ;) You can find the Project in GitHub . Prerequisite: build.gradle First, we have enable dataBinding in app-level build.gradle                           android {                                     dataBinding {                                             enabled = true                                     }                            } Next, we hav...

Android JetPack - Scheduling Tasks with WorkManager

Image
Introduction: WorkManager is one of the Android JetPack component. It is specifically designed for scheduling and managing background tasks. If the app is running, task will be executed in a new thread. Otherwise, WorkManager automatically chooses an appropriate way to do so. It can be AlarmManager, JobScheduler or Firebase JobDispatcher, depends on device's API level and its dependencies. WorkManager Basics: Worker WorkRequest WorkManager WorkInfo (i) Worker: It specifies what task need to be performed. class SampleWorker (context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) { override fun doWork (): ListenableWorker. Result { //do the work here return ListenableWorker. Result . SUCCESS } } (ii) WorkRequest: It represents which Worker should perform the task. Also we can specify any constraints/circumstances, based on which the task should be performed. Constraints can be of Net...