Merge pull request #1605 from NativeScript/on-detached

Fixed Issue #1543: View._onDetached called twice when app is suspended.
This commit is contained in:
Rossen Hristov
2016-02-22 16:52:32 +02:00
2 changed files with 7 additions and 4 deletions

View File

@@ -180,9 +180,10 @@ export class View extends viewCommon.View {
public _removeViewCore(view: viewCommon.View) { public _removeViewCore(view: viewCommon.View) {
super._removeViewCore(view); super._removeViewCore(view);
// TODO: Detach from the context? if (view._context) {
view._onDetached(); view._onDetached();
} }
}
public _onAttached(context: android.content.Context) { public _onAttached(context: android.content.Context) {
if (!context) { if (!context) {
@@ -227,7 +228,9 @@ export class View extends viewCommon.View {
if (child._isAddedToNativeVisualTree) { if (child._isAddedToNativeVisualTree) {
that._removeViewFromNativeVisualTree(child); that._removeViewFromNativeVisualTree(child);
} }
if (child._context) {
child._onDetached(force); child._onDetached(force);
}
return true; return true;
} }
this._eachChildView(eachChild); this._eachChildView(eachChild);

View File

@@ -579,7 +579,7 @@ var NativeActivity = {
onDestroy: function () { onDestroy: function () {
let rootView: View = this.rootView let rootView: View = this.rootView
if (rootView) { if (rootView && rootView._context) {
rootView._onDetached(true); rootView._onDetached(true);
} }