‫Hello my friends and welcome back.
‫We learned about the work manager in Android.
‫Now we're going to monitor and observe the status of the work manager.
‫If it is running, if it is succeeded, if it is failed or canceled, and so on.
‫So for that I'll use work manager dot get instance and I'm going to use get application context.
‫This line of code obtains an instance of the work manager by calling get instance method and passing
‫the application context.
‫Get application context as a parameter.
‫Then I'm going to use get work info by id LiveData method.
‫This method retrieves a live data object that allows you to observe and the status and the progress
‫of a specific work request.
‫You need to pass a unique identifier for the work request whose status you want to observe.
‫In this case, you are using this work request w r w r dot.
‫Get ID to get a unique identifier to the w r work request.
‫Then I'm going to use observe method.
‫Observe method.
‫This code set up an observer on the live data object to listen for changes in the status of the work
‫request.
‫The observer is notified when the status of the request changes, and it can take appropriate actions
‫based on the new status of this work manager.
‫The first parameter is this, which is the owner and the second one is an observer.
‫And we worked with the observer and the live data in the previous section.
‫So please refer to the live data and observer method.
‫The first parameter represents the lifecycle owner and typically an activity or fragment.
‫It specifies the owner's lifecycle to observe live data, and in this case it seems to be within the
‫scope of an activity which is the main activity.
‫The second parameter is a new observer of type work info, and you can see I'm overriding on changed
‫method.
‫The second parameter is an anonymous inner class that defines an observer for the work info class.
‫This is where you define the logic that should be executed when the status of the work request changes.
‫Here, I'll check.
‫If work info doesn't equal to null, then I need to display a toast message telling us the status of
‫this work request states and work info dot get state dot name method.
‫Run the application.
‫Run the work manager status Enqueued running and succeeded.
‫If we open the lookout, we can see it counted to 1000 or 999.
‫Let's understand it better.
‫I'll go to the my worker class here and the do work method.
‫I'll change it to 100,000 to better understand work manager, run the application Logcat.
‫And here click run run.
‫You can see and I'll exit the application.
‫The counting is still running.
‫So congratulations guys.
‫We learned about the work manager status.