diff --git a/tns-core-modules/ui/tab-view/tab-view.android.ts b/tns-core-modules/ui/tab-view/tab-view.android.ts index 3e2b0b816..c88133342 100644 --- a/tns-core-modules/ui/tab-view/tab-view.android.ts +++ b/tns-core-modules/ui/tab-view/tab-view.android.ts @@ -200,10 +200,7 @@ function initializeNativeClasses() { } finishUpdate(container: android.view.ViewGroup): void { - if (this.mCurTransaction != null) { - (this.mCurTransaction).commitNowAllowingStateLoss(); - this.mCurTransaction = null; - } + this._commitCurrentTransaction(); } isViewFromObject(view: android.view.View, object: java.lang.Object): boolean { @@ -211,6 +208,9 @@ function initializeNativeClasses() { } saveState(): android.os.Parcelable { + // Commit the current transaction on save to prevent "No view found for id 0xa" exception on restore. + // Related to: https://github.com/NativeScript/NativeScript/issues/6466 + this._commitCurrentTransaction(); return null; } @@ -221,8 +221,15 @@ function initializeNativeClasses() { getItemId(position: number): number { return position; } - } + private _commitCurrentTransaction() { + if (this.mCurTransaction != null) { + this.mCurTransaction.commitNowAllowingStateLoss(); + this.mCurTransaction = null; + } + } + } + PagerAdapter = FragmentPagerAdapter; } @@ -713,4 +720,4 @@ function tryCloneDrawable(value: android.graphics.drawable.Drawable, resources: } return value; -} \ No newline at end of file +}