Remove pending message when fragment is paused.

Bug: 5422788

Converted the runnable to a message and removed any pending messages in onPause.

Change-Id: I048413ae2abd69a359b1fa2c648d98df3c3ae343
diff --git a/src/com/android/settings/ChooseLockPassword.java b/src/com/android/settings/ChooseLockPassword.java
index 11dd09f..2940442 100644
--- a/src/com/android/settings/ChooseLockPassword.java
+++ b/src/com/android/settings/ChooseLockPassword.java
@@ -27,6 +27,7 @@
 import android.inputmethodservice.KeyboardView;
 import android.os.Bundle;
 import android.os.Handler;
+import android.os.Message;
 import android.preference.PreferenceActivity;
 import android.text.Editable;
 import android.text.InputType;
@@ -44,7 +45,6 @@
 import android.widget.TextView;
 import android.widget.TextView.OnEditorActionListener;
 
-
 public class ChooseLockPassword extends PreferenceActivity {
     public static final String PASSWORD_MIN_KEY = "lockscreen.password_min";
     public static final String PASSWORD_MAX_KEY = "lockscreen.password_max";
@@ -98,10 +98,19 @@
         private boolean mIsAlphaMode;
         private Button mCancelButton;
         private Button mNextButton;
-        private static Handler mHandler = new Handler();
         private static final int CONFIRM_EXISTING_REQUEST = 58;
         static final int RESULT_FINISHED = RESULT_FIRST_USER;
         private static final long ERROR_MESSAGE_TIMEOUT = 3000;
+        private static final int MSG_SHOW_ERROR = 1;
+
+        private Handler mHandler = new Handler() {
+            @Override
+            public void handleMessage(Message msg) {
+                if (msg.what == MSG_SHOW_ERROR) {
+                    updateStage((Stage) msg.obj);
+                }
+            }
+        };
 
         /**
          * Keep track internally of where the user is in choosing a pattern.
@@ -235,6 +244,13 @@
         }
 
         @Override
+        public void onPause() {
+            mHandler.removeMessages(MSG_SHOW_ERROR);
+
+            super.onPause();
+        }
+
+        @Override
         public void onSaveInstanceState(Bundle outState) {
             super.onSaveInstanceState(outState);
             outState.putString(KEY_UI_STAGE, mUiStage.name());
@@ -399,11 +415,9 @@
 
         private void showError(String msg, final Stage next) {
             mHeaderText.setText(msg);
-            mHandler.postDelayed(new Runnable() {
-                public void run() {
-                    updateStage(next);
-                }
-            }, ERROR_MESSAGE_TIMEOUT);
+            Message mesg = mHandler.obtainMessage(MSG_SHOW_ERROR, next);
+            mHandler.removeMessages(MSG_SHOW_ERROR);
+            mHandler.sendMessageDelayed(mesg, ERROR_MESSAGE_TIMEOUT);
         }
 
         public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {