Merge "Improve Toast usage"
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java
index f792bdf..1bbc267 100644
--- a/src/com/android/nfc/NfcService.java
+++ b/src/com/android/nfc/NfcService.java
@@ -2178,11 +2178,11 @@
                         if (!tag.reconnect()) {
                             tag.disconnect();
                             if (mScreenState == ScreenStateHelper.SCREEN_STATE_ON_UNLOCKED) {
-                                if (mToast == null) {
-                                  mToast = Toast.makeText(mContext,
-                                      R.string.tag_read_error, Toast.LENGTH_SHORT);
+                                if (mToast != null) {
+                                    if (mToast.getView().isShown()) mToast.cancel();
                                 }
-                                mToast.setText(R.string.tag_read_error);
+                                mToast = Toast.makeText(mContext, R.string.tag_read_error,
+                                                        Toast.LENGTH_SHORT);
                                 mToast.show();
                             }
                             break;
@@ -2545,12 +2545,12 @@
             if (dispatchResult == NfcDispatcher.DISPATCH_FAIL && !mInProvisionMode) {
                 unregisterObject(tagEndpoint.getHandle());
                 if (mScreenState == ScreenStateHelper.SCREEN_STATE_ON_UNLOCKED) {
-                  if (mToast == null) {
-                    mToast = Toast.makeText(mContext,
-                        R.string.tag_dispatch_failed, Toast.LENGTH_SHORT);
-                  }
-                  mToast.setText(R.string.tag_dispatch_failed);
-                  mToast.show();
+                    if (mToast != null) {
+                        if (mToast.getView().isShown()) mToast.cancel();
+                    }
+                    mToast = Toast.makeText(mContext, R.string.tag_dispatch_failed,
+                                            Toast.LENGTH_SHORT);
+                    mToast.show();
                 }
                 playSound(SOUND_ERROR);
             } else if (dispatchResult == NfcDispatcher.DISPATCH_SUCCESS) {