Skip to content

Commit 0873894

Browse files
authored
fix: early access to context and packageName (#10321)
1 parent 4917bff commit 0873894

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/core/application/application.android.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ export class AndroidApplication extends ApplicationCommon implements IAndroidApp
265265
readonly activityRequestPermissionsEvent = AndroidApplication.activityRequestPermissionsEvent;
266266

267267
private _nativeApp: android.app.Application;
268+
private _context: android.content.Context;
269+
private _packageName: string;
270+
268271
// we are using these property to store the callbacks to avoid early GC collection which would trigger MarkReachableObjects
269272
private lifecycleCallbacks: NativeScriptLifecycleCallbacks;
270273
private componentCallbacks: NativeScriptComponentCallbacks;
@@ -279,6 +282,8 @@ export class AndroidApplication extends ApplicationCommon implements IAndroidApp
279282
}
280283

281284
this._nativeApp = nativeApp;
285+
this._context = nativeApp.getApplicationContext();
286+
this._packageName = nativeApp.getPackageName();
282287

283288
// we store those callbacks and add a function for clearing them later so that the objects will be eligable for GC
284289
this.lifecycleCallbacks = new NativeScriptLifecycleCallbacks();
@@ -381,11 +386,11 @@ export class AndroidApplication extends ApplicationCommon implements IAndroidApp
381386
}
382387

383388
get context() {
384-
return this.nativeApp.getApplicationContext();
389+
return this._context;
385390
}
386391

387392
get packageName() {
388-
return this.nativeApp.getPackageName();
393+
return this._packageName;
389394
}
390395

391396
public registerBroadcastReceiver(intentFilter: string, onReceiveCallback: (context: android.content.Context, intent: android.content.Intent) => void): void {

0 commit comments

Comments
 (0)