From 5f443be0544e9f20e07d93c5a6770de8fa9c5d74 Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Mon, 22 Feb 2016 13:09:08 +0200 Subject: [PATCH] Fixed Issue #1543: View._onDetached called twice when app is suspended. --- ui/core/view.android.ts | 9 ++++++--- ui/frame/frame.android.ts | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ui/core/view.android.ts b/ui/core/view.android.ts index fe4024d90..5af2bb54c 100644 --- a/ui/core/view.android.ts +++ b/ui/core/view.android.ts @@ -180,8 +180,9 @@ export class View extends viewCommon.View { public _removeViewCore(view: viewCommon.View) { super._removeViewCore(view); - // TODO: Detach from the context? - view._onDetached(); + if (view._context) { + view._onDetached(); + } } public _onAttached(context: android.content.Context) { @@ -227,7 +228,9 @@ export class View extends viewCommon.View { if (child._isAddedToNativeVisualTree) { that._removeViewFromNativeVisualTree(child); } - child._onDetached(force); + if (child._context) { + child._onDetached(force); + } return true; } this._eachChildView(eachChild); diff --git a/ui/frame/frame.android.ts b/ui/frame/frame.android.ts index d92eb23ea..4f4e4cbb6 100644 --- a/ui/frame/frame.android.ts +++ b/ui/frame/frame.android.ts @@ -579,7 +579,7 @@ var NativeActivity = { onDestroy: function () { let rootView: View = this.rootView - if (rootView) { + if (rootView && rootView._context) { rootView._onDetached(true); }