Progressbar with Handler is not working when Default Back button is pressed
<p>I have a problem that I have an activity, when I pressed android default back button I want to do some task on the same which needs progress bar therefore I implemented progressbar with Handler in the same method, but Progress Bar doesn't work for me. I don't know why? Please suggest me the right solution regarding the same.</p>

<p><strong>Code:</strong></p>

<pre><code>public boolean onKeyDown(int keyCode, KeyEvent event) 
    {
        if(keyCode == KeyEvent.KEYCODE_BACK &amp;&amp; event.getRepeatCount() == 0)
        {

            backPress++;


            activitySwitchFlag=false;

            video.pause();
            int total=video.getDuration();
            int per=(total*93)/100;
            System.out.println(total+"Percentage"+per);
             try {
                 if(!CompleteFlag)
                 _HomeDBHANDLING();
                }catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                if(video.getCurrentPosition()&gt;per &amp;&amp; ! CompleteFlag)
                {
                    activitySwitchFlag = true;  
                    AlertCalling();

                 System.out.println("True here");       

                 return false;
                }
                try {

                    final ProgressDialog dialog = ProgressDialog.show(VideoPlayer.this, "   Shipface                   ", "Loading....   ", true);

                    final Handler handler = new Handler() {

                       public void handleMessage(Message msg) {

                           Intent myIntent = new Intent(VideoPlayer.this,WatchActivity.class);
                            myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(myIntent);
                            dialog.dismiss();

                          }
                       };

                       final Thread checkUpdate = new Thread() {

                           public void run() {
                               Encrypt();
                               handler.sendEmptyMessage(0);
                           }
                       };
                       checkUpdate.start();

                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                /*if(backPress==1){ 

                EncryptAgainVideo();

                }*/

                finish();

        }

        if (keyCode == KeyEvent.KEYCODE_BACK &amp;&amp; event.getRepeatCount() &gt;= 0) {
            //it is for long press    
                return false;
            }           

        return super.onKeyDown(keyCode, event);

    }
</code></pre>
