MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / getNativeApp

Function getNativeApp

packages/core/application/helpers-common.ts:44–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42 * @returns current application instance, UIApplication on iOS or android.app.Application on Android.
43 */
44export function getNativeApp<T extends NativeApp>(): T {
45 if (__ANDROID__) {
46 if (!nativeApp) {
47 // Try getting it from module - check whether application.android.init has been explicitly called
48 // check whether the com.tns.NativeScriptApplication type exists
49 if (com.tns.NativeScriptApplication) {
50 nativeApp = com.tns.NativeScriptApplication.getInstance();
51 }
52
53 if (!nativeApp && isEmbedded()) {
54 nativeApp = com.tns.embedding.ApplicationHolder.getInstance();
55 }
56
57 // the getInstance might return null if com.tns.NativeScriptApplication exists but is not the starting app type
58 if (!nativeApp) {
59 // TODO: Should we handle the case when a custom application type is provided and the user has not explicitly initialized the application module?
60 const clazz = java.lang.Class.forName('android.app.ActivityThread');
61 if (clazz) {
62 const method = clazz.getMethod('currentApplication', null);
63 if (method) {
64 nativeApp = method.invoke(null, null);
65 }
66 }
67 }
68 }
69 }
70 return nativeApp! as T;
71}
72
73/**
74 * This is called internally to set the native application instance.

Callers 15

loadResourceMethod · 0.90
getCurrentAppPathFunction · 0.90
getApplicationFunction · 0.90
getApplicationFunction · 0.90
ensureSharedPreferencesFunction · 0.90
getImageAsyncMethod · 0.90
getConnectivityManagerFunction · 0.90
initMetricsMethod · 0.90
uuidMethod · 0.90
getNativeApplicationMethod · 0.90
getApplicationContextFunction · 0.90

Calls 2

isEmbeddedFunction · 0.70
getInstanceMethod · 0.45

Tested by

no test coverage detected