<p>In the previous article, we have talked about <strong><span style="color: #008000;"><a style="color: #008000;" href="https://c1ctech.com/android-thread-basics-with-example/">Thread</a></span></strong> . As we know it is possible to access UI components inside the worker thread using some of the methods like</p>
<ul>
<li><span class="s1"><span class="s2"><strong><span style="color: #0000ff;">Activity.runOnUiThread(Runnable)</span>,</strong> </span></span></li>
<li><span style="color: #0000ff;"><span class="s1"><span class="s2"><strong>View.post(Runnable)</strong> </span></span></span></li>
<li><span class="s1"><span class="s2"><span style="color: #0000ff;"><strong>View.postDelayed(Runnable, long)</strong> </span></span></span></li>
</ul>
<p>But there is one more alternative in android i.e <strong class="kp lf"><span style="color: #008000;">Handler</span> </strong>which also allows you communicate back with the UI thread from other background thread. In this article, we will talk about <span style="color: #000000;">Handler</span> in brief.</p>
<h3><span style="color: #000080;"><strong>Main Thread</strong></span></h3>
<p id="33df" class="kf kg cv bc kh b ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="">Android handles all the UI operations and input events from one single thread which is known as Main or UI thread. Android collects all events in this thread in a queue and processes this queue with an instance of the Looper class.</p>
<p id="0d15" class="kf kg cv bc kh b ki kj kk kl km kn ko kp kq kr ks" data-selectable-paragraph="">Android supports Thread class to perform asynchronous processing.</p>
<h3><span style="color: #000080;"><strong>Why Handler</strong></span></h3>
<p data-selectable-paragraph="">By the android single thread model rule, we can not access UI elements (bitmap, text view, button, etc..) directly for another thread defined inside that activity. If you need to update the UI from any worker thread, you need to connect it with the main thread. To achieve this Android comes with the classes i.e. Handler or AsyncTask.</p>
<p><span style="color: #0000ff;"><strong>A Handler allows you to communicate back with the UI thread from other background thread.</strong></span> This is useful in android as android doesn’t allow other threads to communicate directly with UI thread.</p>
<h3><span style="color: #000080;"><strong>How Handler Works</strong></span></h3>
<p><img class="alignnone size-full wp-image-1215" src="https://c1ctech.com/wp-content/uploads/2019/09/Screenshot-2019-09-07-21.50.13.png" alt="Screenshot 2019-09-07 21.50.13" width="1602" height="958" /></p>
<ul>
<li>Activity&#8217;s main UI thread already has a <span style="color: #008000;"><strong>MessageQueue</strong></span> and a <strong><span style="color: #008000;">Looper</span></strong> created by the framework and it can be retrieved by calling <strong>Looper.getMainLooper()</strong>.</li>
<li>The MessageQueue consist of tasks that need to update the UI. This task could be as simple as rendering a button or doing something on click of a button etc. A task may be a <strong><span style="color: #008000;">Message</span></strong> or a <strong><span style="color: #008000;">Runnable</span></strong> object.</li>
<li>If you want to send some task from a background thread to the message queue of the mainThread then we cannot do it directly. But Handler makes it possible.</li>
<li>Handler contains the reference of this message queue and is associated with the Looper of the MainThread. So in the background thread when you send a task (Message or Runnable object) using handler it gets added in the message queue of the MainThread.</li>
<li>The Looper of the main Thread loops through the message queue and take one task at a time and send it to the handler. The handler will then execute the task and update the UI.</li>
</ul>
<h3><strong><span style="color: #000080;">Handler</span></strong></h3>
<ul>
<li>Handler allows you to send and process Message and runnable objects associated with a thread&#8217;s <span style="color: #008000;"><strong>MessageQueue</strong></span>.</li>
<li>Handler instance is associated with a single thread and that thread&#8217;s MessageQueue.</li>
<li>When you create a new Handler, it is bound to the thread/message queue of the thread that is creating it.</li>
<li>It will deliver messages and runnables to that message queue and execute them as they come out of the message queue.</li>
<li>The background thread can communicate with the handler, which will do all of its work on the activity&#8217;s UI thread. For example, if you want to update the progress bar from the background thread what you do is get the handler which belongs to the main thread and simply sends a message updating the progress bar.</li>
</ul>
<h4><span style="color: #000080;"><strong>There are two main uses for a Handler:</strong></span></h4>
<ol>
<li>To schedule messages and runnables to be executed at some point in the future.</p>
</li>
<li>To enqueue an action to be performed on a different thread than your own.</p>
</li>
</ol>
<h4><strong><span style="color: #000080;">There are two ways of communicating with the handler:</span></strong></h4>
<ol>
<li>Messages</li>
<li>Runnable objects</li>
</ol>
<h5><span style="color: #000080;"><strong>Message</strong></span></h5>
<p>Defines a message containing a description and arbitrary data object that can be sent to a handler.</p>
<p>While the constructor of message is public, the best way to get one of these is to call <span style="color: #008000;"><strong>Message.obtain()</strong></span> or one of the Handler <span style="color: #008000;"><strong>obtainMessage</strong></span> methods which will pull them from the pool of recycled objects.</p>
<h4><span style="color: #000080;"><strong>How to send Message objects?</strong></span></h4>
<p><span style="color: #0000ff;"><strong>sendMessage()</strong></span>: Puts the message on the queue immediately.</p>
<p><span style="color: #0000ff;"><strong>sendMessageAtFrontOfQueue()</strong></span>: Puts the message on the queue immediately and places it in front of the message queue so your message takes priority over all others.</p>
<p><span style="color: #0000ff;"><strong>sendmessageAtTime()</strong></span>: puts the message on the queue at the stated time, expressed in the form of milliseconds based on system uptime(Systemclock.uptimeMillis()).</p>
<p><span style="color: #0000ff;"><strong>sendMessageDelayed()</strong></span>: puts the message on the queue after a delay, expressed in milliseconds.</p>
<p><span style="color: #0000ff;"><strong>sendEmptyMessage()</strong></span>: sends an empty message object to the queue, allowing you to skip the obtainMessage() step.</p>
<p>To process these messages, Handler needs to implement <span style="color: #008000;"><strong>handleMessage()</strong></span>, which will be called with each message that appears on the message queue. There the Handler can update the UI as needed.</p>
<p><span style="color: #008000;"><strong><span style="color: #0000ff;">Note</span>: </strong></span><i> </i><span style="color: #008000;"><strong>sendMessage()</strong></span> can be called in any threads but the handler code (i.e <span style="color: #008000;"><strong>handleMessage()</strong></span>) will always be running in the Thread which the Handler&#8217;s Looper resides in.</p>
<p>Now to understand the working of <span style="color: #0000ff;"><strong>Thread Looper Handler</strong></span> when the task in the MessageQueue will be a <strong><span style="color: #008000;">message</span></strong> look at the below diagram:</p>
<p><img class="alignnone size-full wp-image-1216" src="https://c1ctech.com/wp-content/uploads/2019/09/Screenshot-2019-09-07-21.52.28.png" alt="Screenshot 2019-09-07 21.52.28" width="1776" height="834" /></p>
<ul>
<li>The main thread has message queue which consists of lot&#8217;s of messages and a looper which loops through the message queue.</li>
<li>The handler is capable of two things that can handle messages that come from the looper and can also send messages from a different thread.</li>
<li>Thread1 let&#8217;s say want to send message to the main thread indicating to update the progress bar so what you do is you get the handler reference and you call <strong><span style="color: #008000;">sendMessage</span></strong> of the Handler and that message goes inside the message queue of the main thread.</li>
<li>The looper is going to run one message at a time and ultimately when it comes to your message the looper is going to open the message up and is going to forward the message to the handler.</li>
<li>Now the handler object is going to have this method called <span style="color: #008000;"><strong>handleMessage</strong></span> inside which whatever code you have written is going to be executed in the main thread.</li>
<li>Each thread can have its own looper and its own handler, for now, the main thread is the one who has its own looper that&#8217;s gonna take one message at a time and its own handler who&#8217;s gonna pick one message up and run it. Other thread can use a reference to this handler to send messages to the main thread.</li>
</ul>
<h4><span style="color: #000080;"><strong>Runnable</strong></span></h4>
<p>Runnable is an interface which contains one single method run() with no arguments. The post versions methods of Handler class accept the Runnable objects to be added to the message queue and the code written inside the run method will be executed by the thread to which this handler is attached.</p>
<h4><span style="color: #000080;"><strong>How to send Runnable objects?</strong></span></h4>
<p><span style="color: #0000ff;"><strong>post(Runnable r)</strong></span>: Causes the Runnable r to be added to the message queue. The runnable will be run on the thread to which this handler is attached.</p>
<p><span style="color: #0000ff;"><strong>postAtTime(Runnable r, long uptimeMillis)</strong></span><strong>: </strong>Causes the Runnable r to be added to the message queue, to be run at a specific time given by <var>uptimeMillis</var>.</p>
<p><span style="color: #0000ff;"><strong>postDelayed(Runnable r, long delayMillis)</strong></span>: Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.</p>
<p>In the above <span style="color: #0000ff;"><strong>Thread Looper Handler</strong></span> diagram when you want to send a Runnable object from the background thread (Thread 1) to the main thread using the post method of the handler then it gets added in the message queue of the main thread and then it gets executed inside the thread to which handler is attached (the UI thread).</p>
<h3><span style="color: #000080;"><strong>Handler Example</strong></span></h3>
<p>Now let&#8217;s take an example in which we are downloading an image over the network in an <span style="color: #008000;"><strong>imageView</strong></span> on button click. In the below example we are communicating with handler using both message and Runnable object.</p>
<p><span style="color: #0000ff;"><strong>MainActivity.java</strong></span></p>
<!-- WP QUADS Content Ad Plugin v. 2.0.98.1 -->
<div class="quads-location quads-ad2" id="quads-ad2" style="float:none;margin:0px;">

</div>

<pre class="p1"><span class="s1"><b>package </b></span><span class="s2">trendlife.handlerdemo;</span>

<span class="s1"><b>import </b></span><span class="s2">android.graphics.Bitmap;</span>

<span class="s1"><b>import </b></span><span class="s2">android.graphics.BitmapFactory;</span>

<span class="s1"><b>import </b></span><span class="s2">android.os.Bundle;</span>

<span class="s1"><b>import </b></span><span class="s2">android.os.Handler;</span>

<span class="s1"><b>import </b></span><span class="s2">android.os.Message;</span>

<span class="s1"><b>import </b></span><span class="s2">android.support.v7.app.AppCompatActivity;</span>

<span class="s1"><b>import </b></span><span class="s2">android.util.Log;</span>

<span class="s1"><b>import </b></span><span class="s2">android.view.View;</span>

<span class="s1"><b>import </b></span><span class="s2">android.widget.ImageView;</span>

<span class="s1"><b>import </b></span><span class="s2">android.widget.ProgressBar;</span>

<span class="s1"><b>import </b></span><span class="s2">android.widget.TextView;</span>

<span class="s1"><b>import </b></span><span class="s2">android.widget.Toast;</span>

<span class="s1"><b>import </b></span><span class="s2">java.io.IOException;</span>

<span class="s1"><b>import </b></span><span class="s2">java.io.InputStream;</span>

<span class="s1"><b>import </b></span><span class="s2">java.net.HttpURLConnection;</span>

<span class="s1"><b>import </b></span><span class="s2">java.net.MalformedURLException;</span>

<span class="s1"><b>import </b></span><span class="s2">java.net.URL;</span>

<span class="s1"><b>public class </b></span><span class="s2">MainActivity </span><span class="s1"><b>extends </b></span><span class="s2">AppCompatActivity {</span>

<span class="s2"><span class="Apple-converted-space"> </span>ImageView </span><span class="s3"><b>imageView</b></span><span class="s2">;</span>

<span class="s2"><span class="Apple-converted-space"> </span>Handler </span><span class="s3"><b>handler</b></span><span class="s2">;</span>

<span class="s2"><span class="Apple-converted-space"> </span>ProgressBar </span><span class="s3"><b>progressBar</b></span><span class="s2">;</span>

<span class="s4"><span class="Apple-converted-space"> </span>TextView </span><span class="s2"><b>tv_loading_image</b></span><span class="s4">;</span>

<span class="s2"><span class="Apple-converted-space"> </span>Boolean </span><span class="s3"><b>progressStatus </b></span><span class="s2">= </span><span class="s1"><b>false</b></span><span class="s2">;</span>

<span class="s4"><span class="Apple-converted-space"> </span></span><span class="s2">@Override</span>

<span class="s5"><span class="Apple-converted-space"> </span></span><span class="s1"><b>protected void </b></span><span class="s2">onCreate(Bundle savedInstanceState) {</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s1"><b>super</b></span><span class="s2">.onCreate(savedInstanceState);</span>

<span class="s2"><span class="Apple-converted-space"> </span>setContentView(R.layout.</span><span class="s3"><b><i>activity_main</i></b></span><span class="s2">);</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s3"><b>imageView </b></span><span class="s2">= findViewById(R.id.</span><span class="s3"><b><i>image</i></b></span><span class="s2">);</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s3"><b>tv_loading_image </b></span><span class="s2">= findViewById(R.id.</span><span class="s3"><b><i>tv_loading</i></b></span><span class="s2">);</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s3"><b>progressBar </b></span><span class="s2">= findViewById(R.id.</span><span class="s3"><b><i>progressbar</i></b></span><span class="s2">);</span>

<span class="s4"><span class="Apple-converted-space"> </span></span><span style="color: #008000;"><strong><span class="s2"><i>//As we have created handler inside the UI thread so this handler get attached with the Looper,message queue of the UI thread.</i></span></strong></span>

<span class="s6"><i><span class="Apple-converted-space"> </span></i></span><span class="s3"><b>handler </b></span><span class="s2">= </span><span class="s1"><b>new </b></span><span class="s2">Handler() {</span>

<span class="s4"><span class="Apple-converted-space"> </span></span><strong><span class="s2" style="color: #008000;"><i>//the code inside the handleMessage() run inside the main thread and handler execute the code and then update the UI.</i></span></strong>

<span class="s2"><i><span class="Apple-converted-space"> </span></i></span><span class="s5">@Override</span>

<span class="s5"><span class="Apple-converted-space"> </span></span><span class="s1"><b>public void </b></span><span class="s2">handleMessage(Message msg) {</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s3"><b>progressStatus </b></span><span class="s2">= </span><span class="s1"><b>false</b></span><span class="s2">;</span>

<span class="s2"><span class="Apple-converted-space"> </span>Object obj = msg.getData().getParcelable(</span><span class="s7"><b>"MyObject"</b></span><span class="s2">);</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s3"><b>imageView</b></span><span class="s2">.setImageBitmap((Bitmap) obj);</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s3"><b>imageView</b></span><span class="s2">.setVisibility(View.</span><span class="s3"><b><i>VISIBLE</i></b></span><span class="s2">);</span>

<span class="s2"><span class="Apple-converted-space"> </span>Toast.<i>makeText</i>(getApplicationContext(), </span><span class="s7"><b>"Image downloaded"</b></span><span class="s2">, Toast.</span><span class="s3"><b><i>LENGTH_SHORT</i></b></span><span class="s2">).show();</span>

<span class="s2"><span class="Apple-converted-space"> </span>}</span>

<span class="s2"><span class="Apple-converted-space"> </span>};</span>

<span class="s2"><span class="Apple-converted-space"> </span>}</span>

<span class="s4"><span class="Apple-converted-space"> </span></span><strong><span class="s2" style="color: #008000;"><i>//this method is called on DownloadImage button click</i></span></strong>

<span class="s6"><i><span class="Apple-converted-space"> </span></i></span><span class="s1"><b>public void </b></span><span class="s2">downloadImage(View view) {</span>

<span class="s2"><span class="Apple-converted-space"> </span>Log.<i>i</i>(</span><span class="s7"><b>"Button"</b></span><span class="s2">, </span><span class="s7"><b>"Tapped"</b></span><span class="s2">);</span>

<span class="s4"><span class="Apple-converted-space"> </span></span><span class="s2"><b>progressStatus </b></span><span class="s4">= </span><span class="s1"><b>true</b></span><span class="s4">;</span>

<span class="s4"><span class="Apple-converted-space"> </span></span><strong><span class="s2" style="color: #008000;"><i>//background thread started</i></span></strong>

<span class="s6"><i><span class="Apple-converted-space"> </span></i></span><span class="s2">DownloadImage downloadImage = </span><span class="s1"><b>new </b></span><span class="s2">DownloadImage();</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s1"><b>new </b></span><span class="s2">Thread(downloadImage).start();</span>

<span class="s2"><span class="Apple-converted-space"> </span>}</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s1"><b>class </b></span><span class="s2">DownloadImage </span><span class="s1"><b>implements </b></span><span class="s2">Runnable {</span>

<span class="s4"><span class="Apple-converted-space"> </span></span><span class="s2">@Override</span>

<span class="s5"><span class="Apple-converted-space"> </span></span><span class="s2"><b>public void </b></span><span class="s4">run() {</span>

<span class="s2"><span class="Apple-converted-space"> </span>URL url;</span>

<span class="s2"><span class="Apple-converted-space"> </span>HttpURLConnection httpURLConnection;</span>

<span class="s2"><span class="Apple-converted-space"> </span>Bitmap result = </span><span class="s1"><b>null</b></span><span class="s2">;</span>

<span class="s4"><span class="Apple-converted-space"> </span></span><strong><span class="s2" style="color: #008000;"><i>//communicating with handler using Runnable object</i></span></strong>

<span class="s6"><i><span class="Apple-converted-space"> </span></i></span><span class="s3"><b>handler</b></span><span class="s2">.post(</span><span class="s1"><b>new </b></span><span class="s2">Runnable() {</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s5">@Override</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s1"><b>public void </b></span><span class="s4">run() {</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s1"><b>if </b></span><span class="s2">(</span><span class="s3"><b>progressStatus </b></span><span class="s2">= </span><span class="s1"><b>true</b></span><span class="s2">) {</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s3"><b>tv_loading_image</b></span><span class="s2">.setText(</span><span class="s7"><b>"Loading Image..."</b></span><span class="s2">);</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s3"><b>tv_loading_image</b></span><span class="s2">.setVisibility(View.</span><span class="s3"><b><i>VISIBLE</i></b></span><span class="s2">);</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s3"><b>progressBar</b></span><span class="s2">.setVisibility(View.</span><span class="s3"><b><i>VISIBLE</i></b></span><span class="s2">);</span>

<span class="s2"><span class="Apple-converted-space"> </span>}</span>

<span class="s2"><span class="Apple-converted-space"> </span>}</span>

<span class="s2"><span class="Apple-converted-space"> </span>});</span>

<span class="s4"><span class="Apple-converted-space"> </span></span><strong><span class="s2" style="color: #008000;"><i>//getting image bitmap</i></span></strong>

<span class="s2"><i><span class="Apple-converted-space"> </span></i></span><span class="s1"><b>try </b></span><span class="s4">{</span>

<span class="s4"><span class="Apple-converted-space"> </span>url = </span><span class="s1"><b>new </b></span><span class="s4">URL(</span><span class="s2"><b>"https://vignette.wikia.nocookie.net/disney/images/0/0a/ElsaPose.png/revision/latest?cb=20170221004839"</b></span><span class="s4">);</span>

<span class="s2"><span class="Apple-converted-space"> </span>httpURLConnection = (HttpURLConnection) url.openConnection();</span>

<span class="s2"><span class="Apple-converted-space"> </span>httpURLConnection.connect();</span>

<span class="s2"><span class="Apple-converted-space"> </span>InputStream in = httpURLConnection.getInputStream();</span>

<span class="s2"><span class="Apple-converted-space"> </span>result = BitmapFactory.<i>decodeStream</i>(in);</span>

<span class="s2"><span class="Apple-converted-space"> </span>} </span><span class="s1"><b>catch </b></span><span class="s2">(MalformedURLException e) {</span>

<span class="s2"><span class="Apple-converted-space"> </span>e.printStackTrace();</span>

<span class="s2"><span class="Apple-converted-space"> </span>} </span><span class="s1"><b>catch </b></span><span class="s2">(IOException e) {</span>

<span class="s2"><span class="Apple-converted-space"> </span>e.printStackTrace();</span>

<span class="s2"><span class="Apple-converted-space"> </span>}</span>

<span class="s4"><span class="Apple-converted-space"> </span></span><strong><span class="s2" style="color: #008000;"><i>//communicating with handler using Message object</i></span></strong>

<span class="s6"><i><span class="Apple-converted-space"> </span></i></span><span class="s2">Message message = </span><span class="s3"><b>handler</b></span><span class="s2">.obtainMessage();</span>

<span class="s2"><span class="Apple-converted-space"> </span>Bundle bundle = </span><span class="s1"><b>new </b></span><span class="s2">Bundle();</span>

<span class="s2"><span class="Apple-converted-space"> </span>bundle.putParcelable(</span><span class="s7"><b>"MyObject"</b></span><span class="s2">, result);</span>

<span class="s2"><span class="Apple-converted-space"> </span>message.setData(bundle);</span>

<span class="s2"><span class="Apple-converted-space"> </span></span><span class="s3"><b>handler</b></span><span class="s2">.sendMessage(message);</span>

<span class="s2"><span class="Apple-converted-space"> </span>}</span>

<span class="s2"><span class="Apple-converted-space"> </span>}</span>

<span class="s2">}</span></pre>
<p><strong><span style="color: #0000ff;">activity_main.xml</span></strong></p>
<pre><;?xml version="1.0" encoding="utf-8"?>;
<;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".MainActivity">;


 <;TextView
 android:id="@+id/tv_loading"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerInParent="true"
 android:gravity="center"
 android:text="Loading Image..."
 android:textColor="@color/colorAccent"
 android:textSize="20sp"
 android:textStyle="bold"
 android:visibility="invisible"/>;

 <;ProgressBar
 android:id="@+id/progressbar"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerInParent="true"
 android:layout_marginTop="10dp"
 android:visibility="invisible"
 android:gravity="center"
 android:layout_below="@+id/tv_loading"/>;


 <;LinearLayout
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerInParent="true"
 android:gravity="center"
 android:orientation="vertical">;


 <;ImageView
 android:id="@+id/image"
 android:layout_width="350dp"
 android:layout_height="350dp"
 android:background="@drawable/border_image"
 android:visibility="invisible" />;


 <;Button
 android:id="@+id/btn_download"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginTop="10dp"
 android:background="@android:color/holo_blue_bright"
 android:onClick="downloadImage"
 android:padding="10dp"
 android:text="download image"
 android:textColor="@android:color/black"
 android:textStyle="bold" />;

 <;/LinearLayout>;


<;/RelativeLayout>;</pre>
<p>When you run the application <strong><span style="color: #0000ff;">HandlerDemo</span></strong> it will look like this as shown below:</p>
<p><img class=" wp-image-1221 aligncenter" src="https://c1ctech.com/wp-content/uploads/2019/09/handlerdemo.gif" alt="handlerdemo" width="384" height="683" /></p>
<p>I hope this article will help you in understanding what is Handler, why we use it, it&#8217;s working and its example.

