Skip to content

Commit 88e355d

Browse files
committed
fix: application instance creation occurs only within Application.run
1 parent 4a384ca commit 88e355d

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

packages/core/application/index.android.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,18 @@ export interface AndroidApplication {
159159
on(event: 'activityRequestPermissions', callback: (args: AndroidActivityRequestPermissionsEventData) => void, thisArg?: any);
160160
}
161161

162-
const androidApp = new AndroidApplication();
162+
let androidApp: AndroidApplication;
163163
export { androidApp as android };
164-
appCommon.setApplication(androidApp);
165164

166165
let mainEntry: NavigationEntry;
167166
let started = false;
168167

169168
export function run(entry?: NavigationEntry | string) {
169+
if (!androidApp) {
170+
androidApp = new AndroidApplication();
171+
appCommon.setApplication(androidApp);
172+
}
173+
170174
if (started) {
171175
throw new Error('Application is already started.');
172176
}

packages/core/application/index.ios.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,9 @@ export class iOSApplication implements iOSApplicationDefinition {
349349
}
350350

351351
/* tslint:disable */
352-
const iosApp = new iOSApplication();
352+
let iosApp: iOSApplication;
353353
/* tslint:enable */
354354
export { iosApp as ios };
355-
setApplication(iosApp);
356355

357356
// attach on global, so it can be overwritten in NativeScript Angular
358357
(<any>global).__onLiveSyncCore = function (context?: ModuleContext) {
@@ -389,6 +388,11 @@ export function getRootView() {
389388

390389
let started = false;
391390
export function run(entry?: string | NavigationEntry) {
391+
if (!iosApp) {
392+
iosApp = new iOSApplication();
393+
setApplication(iosApp);
394+
}
395+
392396
mainEntry = typeof entry === 'string' ? { moduleName: entry } : entry;
393397
started = true;
394398

0 commit comments

Comments
 (0)