From 9847c9f8037a48f854d0504097ea768c3a6f61ee Mon Sep 17 00:00:00 2001 From: atanasovg Date: Mon, 6 Jun 2016 10:01:18 +0300 Subject: [PATCH] Improve the default nativeApp initialization. --- tns-core-modules/utils/utils.android.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tns-core-modules/utils/utils.android.ts b/tns-core-modules/utils/utils.android.ts index b0526a9d0..9242d3695 100644 --- a/tns-core-modules/utils/utils.android.ts +++ b/tns-core-modules/utils/utils.android.ts @@ -156,7 +156,9 @@ export module ad { if(com.tns.NativeScriptApplication) { nativeApp = com.tns.NativeScriptApplication.getInstance(); } - else { + + // the getInstance might return null if com.tns.NativeScriptApplication exists but is not the starting app type + if(!nativeApp) { // check whether application.android.init has been explicitly called let application = require("application"); nativeApp = application.android.nativeApp; @@ -173,6 +175,7 @@ export module ad { } } + // we cannot work without having the app instance if(!nativeApp) { throw new Error("Failed to retrieve native Android Application object. If you have a custom android.app.Application type implemented make sure that you've called the '.android.init' method.") }