Improve the default nativeApp initialization.

This commit is contained in:
atanasovg
2016-06-06 10:01:18 +03:00
parent 87b0f53c3d
commit 9847c9f803

View File

@@ -156,7 +156,9 @@ export module ad {
if(com.tns.NativeScriptApplication) { if(com.tns.NativeScriptApplication) {
nativeApp = com.tns.NativeScriptApplication.getInstance(); 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 // check whether application.android.init has been explicitly called
let application = require("application"); let application = require("application");
nativeApp = application.android.nativeApp; nativeApp = application.android.nativeApp;
@@ -173,6 +175,7 @@ export module ad {
} }
} }
// we cannot work without having the app instance
if(!nativeApp) { 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 '<application-module>.android.init' method.") 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 '<application-module>.android.init' method.")
} }