Skip to content

[Android] Frame and TabView restore a collected snapshot as background on load ("Attempt to use cleared object reference"), page stays blank #11678

Backlog

Description

@anjak03

Issue Description

Issue description
A runtime error occurs on Android when using markingMode: 'none'.

When the parent fragment of a Frame or TabView is removed and the view subsequently loads again, onLoaded() throws an Attempt to use cleared object reference exception from _applyBackground().

The exception interrupts the loading process, preventing the remaining page content from loading and resulting in a blank screen. In the case of TabView, the execution of setAdapterItems() is also skipped.

Issue #7867 was closed with a recommendation to open a new issue if the problem persists in a newer version of core. The issue is still reproducible in version 9.1.4, and the relevant implementation remains unchanged on main.

What happens

  1. The parent fragment is removed. onDestroyView() in frame-helper-for-android.ts (Frame) and tab-view/index.android.ts (TabView) sets a BitmapDrawable snapshot of the content as the native background and stores _originalBackground.
  2. During the next onLoaded(), both Frame and TabView restore the background by executing:
    this.backgroundColor = null;
    this.backgroundColor = this._originalBackground;
    3.The first assignment triggers onBackgroundOrBorderPropertyChanged(), which initializes nativeView._cachedDrawable with nativeView.getBackground() if it is still undefined.
    At this point, the native background is the snapshot, meaning the temporary snapshot is incorrectly cached as the view's default drawable.
  3. During a subsequent removal and load cycle, setting backgroundColor = null attempts to restore _cachedDrawable.
    With markingMode: 'none', the underlying Java BitmapDrawable has already been garbage collected, causing _applyBackground() to throw an exception.

Suggested fix
Initialize _cachedDrawable before onDestroyView() replaces the native background with the snapshot.

If _cachedDrawable is still undefined, set it to the current value returned by getBackground(). This ensures that the temporary snapshot is never cached as the default background.

Relevant log output
Error: Failed to get Java object by ID. id=7633,
class=android/graphics/drawable/BitmapDrawable.
com.tns.NativeScriptException: Attempt to use cleared object reference id=7633
_applyBackground(vendor.js)
at onBackgroundOrBorderPropertyChanged(vendor.js)
at _redrawNativeBackground(vendor.js)
at backgroundInternal:setNative
at setLocalValue(vendor.js)
at valueChanged(vendor.js)
at set(vendor.js)
at set backgroundColor(vendor.js)
at onLoaded(vendor.js)
at callFunctionWithSuper(vendor.js)
at callLoaded(vendor.js)
at loadView(vendor.js)

Environment

Dependency Version
@nativescript/core 9.1.4
@nativescript/android 9.1.1
@nativescript/angular 18.0.1
Angular 18
Marking mode none
Reproduction environment Android 16 emulator

Related issues

Please accept these terms

Activity

  1. added
    bug-pending-triage
    on Nov 25, 2026
  2. added and removed
    bug-pending-triage
    on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions