NativeScript/NativeScript · error · Error
NativeWindow: Activity is no longer available.
Error message
NativeWindow: Activity is no longer available.
What it means
The Android NativeWindow applies content by setting it as the root view of its backing Activity. If this.activity is null/falsy - meaning the Activity reference is gone (app relaunched, activity destroyed after backgrounding, or window created without a live activity) - _setNativeContent() throws because there is no native window to attach the view to.
Source
Thrown at packages/core/native-window/native-window.android.ts:104
get activity(): androidx.appcompat.app.AppCompatActivity | undefined {
return this._activity?.deref();
}
get android() {
const activity = this.activity;
if (!activity) {
return undefined;
}
return { activity };
}
/**
* Platform-specific: apply the view as root content of this Activity.
*/
protected _setNativeContent(view: View): void {
const activity = this.activity;
if (!activity) {
throw new Error('NativeWindow: Activity is no longer available.');
}
const callbacks: AndroidActivityCallbacks = (activity as any)[CALLBACKS];
if (!callbacks) {
throw new Error('NativeWindow: Cannot find activity callbacks.');
}
callbacks.resetActivityContent(activity, view);
}
/**
* Close this window by finishing the activity.
*/
close(): void {
if (this.isPrimary) {
console.log('NativeWindow: Cannot close the primary window.');
return;
}
View on GitHub (pinned to 6800aefa65)
Solutions
- Recreate the NativeWindow (or re-resolve its activity) before setting content on Android.
- Check window.activity (or an isAlive/isOpen check) before calling setContent().
- Cancel pending async work/timers that reference the window when the activity is destroyed.
- Listen for application lifecycle events (suspend/resume) to refresh window references.
Example fix
// before
pendingWindow.setContent(newView); // activity already destroyed
// after
if (pendingWindow && pendingWindow.activity) {
pendingWindow.setContent(newView);
} Defensive patterns
Strategy: validation
Validate before calling
if (!win || !win.activity) {
win = recreateNativeWindow(); // activity gone; rebuild before setting content
}
win._setNativeContent(view); Type guard
function canApplyNativeContent(win) {
return !!win && typeof win.activity === 'object' && win.activity !== null && !win.activity.isFinishing();
} Try / catch
try {
win.setContent(view);
} catch (e) {
if (String(e.message).includes('Activity is no longer available')) {
win = recreateNativeWindow();
win.setContent(view);
} else throw e;
} Prevention
- Don't cache NativeWindow references across activity destruction/recreation.
- Cancel timers/async tasks on application suspend.
- Check activity availability before every Android-specific native-window call.
When it happens
Trigger: Calling setContent()/open() on a NativeWindow after its Activity has been destroyed (e.g. after process death and recreation, or on Android when the app was backgrounded and the activity finished).
Common situations: Restoring UI from saved state after Android kills the activity; holding a NativeWindow reference across configuration changes (rotation); delayed callbacks/timers firing after activity teardown.
Related errors
- NativeWindow: Cannot find activity callbacks.
- Application.android already initialized.
- Failed to retrieve native Android Application object. If you
- Application is already started.
- Cannot find android activity.
AI-assisted analysis of NativeScript/NativeScript@6800aefa65 (2026-08-30).
Data as JSON: /api/errors/2dad549543810426.
Report an issue: GitHub.