Sometime, Settings app crash when AllowBindAppWidgetActivity closing

Process: com.android.settings
E AndroidRuntime: java.lang.RuntimeException:
Unable to destroy activity {com.android.settings/
com.android.settings.AllowBindAppWidgetActivity}:
java.lang.IllegalArgumentException: Receiver not registered:
android.app.Activity$1@5817135

Change-Id: I0f8b61f4c1772b43bffd949928ccaafd295f5fac
Signed-off-by: Mikhail Malakhov <malakhv@gmail.com>
diff --git a/src/com/android/settings/AllowBindAppWidgetActivity.java b/src/com/android/settings/AllowBindAppWidgetActivity.java
index c3bf78a..b015b68 100644
--- a/src/com/android/settings/AllowBindAppWidgetActivity.java
+++ b/src/com/android/settings/AllowBindAppWidgetActivity.java
@@ -51,9 +51,8 @@
     private boolean mClicked;
 
     public void onClick(DialogInterface dialog, int which) {
+        mClicked = true;
         if (which == AlertDialog.BUTTON_POSITIVE) {
-            // By default, set the result to cancelled
-            setResult(RESULT_CANCELED);
             if (mAppWidgetId != -1 && mComponentName != null && mCallingPackage != null) {
                 try {
                     final boolean bound = mAppWidgetManager.bindAppWidgetIdIfAllowed(mAppWidgetId,
@@ -79,15 +78,18 @@
         finish();
     }
 
+    @Override
     protected void onPause() {
-        if (isDestroyed() && !mClicked) {
-            setResult(RESULT_CANCELED);
+        if (!mClicked) { // RESULT_CANCELED
+            finish();
         }
-        super.onDestroy();
+        super.onPause();
     }
 
+    @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        setResult(RESULT_CANCELED); // By default, set the result to cancelled
         Intent intent = getIntent();
         CharSequence label = "";
         if (intent != null) {
@@ -109,7 +111,6 @@
                 mComponentName = null;
                 mCallingPackage = null;
                 Log.v("BIND_APPWIDGET", "Error getting parameters");
-                setResult(RESULT_CANCELED);
                 finish();
                 return;
             }