How to stop a thread in android which is started using PostDelayed method
<p>I Have created a thread in my android application to fetch data by making http request to a server.
I have used following code to make thread</p>

<p>I have defined handler as </p>

<pre><code>private Handler mHandler = new Handler();



final Runnable mUpdateTimeTask = new Runnable() {
                                           public void run() {

                                                    dilogShow=false;
                                                   getappdata();

                                           }
                                   };
</code></pre>

<p>and to start this thread i have used following line of code</p>

<pre><code>mHandler.postDelayed(mUpdateTimeTask, 20000);
</code></pre>

<p>and to stop it i am using following line of code which works some times but not always.</p>

<pre><code>mHandler.removeCallbacks(mUpdateTimeTask);
</code></pre>

<p>the getappdata() function is as follows:</p>

<pre><code>public void getappdata() {

           final Handler handler = new Handler() {
                   @Override
                   public void handleMessage(Message message) {
                           // managing UI here

                   };
           };
           Thread thread = new Thread() {

                   @Override
                   public void run() {
                      // sending http request here
                   };
           };        
           thread.start();
</code></pre>

<p>}</p>

<p>please help me</p>
