Course Content

Course Content

Description

Handler class in Android

In this video tutorial, we will learn about the Handler Class in Android.

Android Handler class comes from the package android.os.Handler package and is most commonly used for multithreading in Android.

A Handler object registers itself with the thread in which it is created. It provides a channel to send data to this thread.

For example, if we are making an application that contains multiple activities, and when we run it, it will firstlmake a Main/UI thread in which all of our activities will run, as there is only one Main thread in which all the activities run, we are going to make different threads to make our application flexible.

Now if we want our sub-threads to give the response to our main thread, or to handle them, there comes the concept of 'Handler'.

We use Handler to post multiple data. When we want to communicate our main activity through UI thread, Handler is used.

Why we use handlers with Thread?

When we install an application in Android then it creates a thread for that application called MAIN UI Thread.

Instantiating Android Handler Class

There are following two ways in which the Android handler class is usually instantiated for supporting multi-threading :

  • Through default constructor -

Handler handlerobject=new Handler();

  • Through parameterized constructor -

Handler handlerobject=new Handler(Runnable runnableobject,Handler.Callback callbackObject);

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
297K+ Downloads
App Download Section Circle 1
4.5 Rating
App Download Section Circle 2
10K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere