Merge "Clean up listeners when view is destroyed." into klp-dev
diff --git a/InCallUI/src/com/android/incallui/AnswerPresenter.java b/InCallUI/src/com/android/incallui/AnswerPresenter.java
index 3dc751f..4c0f1d6 100644
--- a/InCallUI/src/com/android/incallui/AnswerPresenter.java
+++ b/InCallUI/src/com/android/incallui/AnswerPresenter.java
@@ -46,6 +46,18 @@
     }
 
     @Override
+    public void onUiUnready(AnswerUi ui) {
+        super.onUiUnready(ui);
+        CallList.getInstance().removeListener(this);
+
+        // This is necessary because the activity can be destroyed while an incoming call exists.
+        // This happens when back button is pressed while incoming call is still being shown.
+        if (mCallId != Call.INVALID_CALL_ID) {
+            CallList.getInstance().removeCallUpdateListener(mCallId, this);
+        }
+    }
+
+    @Override
     public void onCallListChange(CallList callList) {
         // no-op
     }