Unregister the NFC callback onPause.
This prevents us from leaking BrowserActivity when we go to
the background.
Bug: 5233864
Change-Id: Idf59de67637c8c9eb39ea9f8b9cb93320c4afa99
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index adc2677..ff1ad0e 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -253,8 +253,6 @@
}
void start(final Bundle icicle, final Intent intent) {
- NfcHandler.register(mActivity, this);
-
boolean noCrashRecovery = intent.getBooleanExtra(NO_CRASH_RECOVERY, false);
if (icicle != null || noCrashRecovery) {
doStart(icicle, intent);
@@ -637,6 +635,7 @@
mNetworkHandler.onPause();
WebView.disablePlatformNotifications();
+ NfcHandler.unregister(mActivity);
}
void onSaveInstanceState(Bundle outState) {
@@ -670,6 +669,7 @@
mUi.onResume();
mNetworkHandler.onResume();
WebView.enablePlatformNotifications();
+ NfcHandler.register(mActivity, this);
}
private void releaseWakeLock() {
diff --git a/src/com/android/browser/NfcHandler.java b/src/com/android/browser/NfcHandler.java
index 6147aea..1b34df2 100644
--- a/src/com/android/browser/NfcHandler.java
+++ b/src/com/android/browser/NfcHandler.java
@@ -45,7 +45,18 @@
if (adapter == null) {
return; // NFC not available on this device
}
- adapter.setNdefPushMessageCallback(new NfcHandler(controller), activity);
+ NfcHandler handler = null;
+ if (controller != null) {
+ handler = new NfcHandler(controller);
+ }
+
+ adapter.setNdefPushMessageCallback(handler, activity);
+ }
+
+ public static void unregister(Activity activity) {
+ // Passing a null controller causes us to disable
+ // the callback and release the ref to out activity.
+ register(activity, null);
}
public NfcHandler(Controller controller) {