Skip to content

Commit 0ead3cc

Browse files
committed
Merge pull request #471 from NativeScript/atanasovg/build-template-polish
Make the default template work without the assumption that com.tns.NativeScriptApplication is extended through JS.
2 parents e7db2e2 + 0460e98 commit 0ead3cc

2 files changed

Lines changed: 13 additions & 36 deletions

File tree

build/project-template-gradle/src/main/java/com/tns/NativeScriptApplication.java

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import android.app.Application;
44

5-
@JavaScriptImplementation(javaScriptFile = "./tns_modules/application/application.js")
6-
public class NativeScriptApplication extends android.app.Application implements com.tns.NativeScriptHashCodeProvider {
5+
public class NativeScriptApplication extends android.app.Application {
76

87
private static NativeScriptApplication thiz;
98

@@ -12,40 +11,8 @@ public NativeScriptApplication() {
1211
}
1312

1413
public void onCreate() {
14+
super.onCreate();
1515
new RuntimeHelper(this).initRuntime();
16-
if (Runtime.isInitialized()) {
17-
java.lang.Object[] params = null;
18-
com.tns.Runtime.callJSMethod(this, "onCreate", void.class, params);
19-
} else {
20-
super.onCreate();
21-
}
22-
}
23-
24-
public void onLowMemory() {
25-
if (Runtime.isInitialized()) {
26-
java.lang.Object[] params = null;
27-
com.tns.Runtime.callJSMethod(this, "onLowMemory", void.class, params);
28-
} else {
29-
super.onLowMemory();
30-
}
31-
}
32-
33-
public void onTrimMemory(int level) {
34-
if (Runtime.isInitialized()) {
35-
java.lang.Object[] params = new Object[1];
36-
params[0] = level;
37-
com.tns.Runtime.callJSMethod(this, "onTrimMemory", void.class, params);
38-
} else {
39-
super.onTrimMemory(level);
40-
}
41-
}
42-
43-
public boolean equals__super(java.lang.Object other) {
44-
return super.equals(other);
45-
}
46-
47-
public int hashCode__super() {
48-
return super.hashCode();
4916
}
5017

5118
public static Application getInstance() {

build/project-template-gradle/src/main/java/com/tns/RuntimeHelper.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public boolean hasErrorIntent()
4444

4545
public void initRuntime()
4646
{
47+
if (Runtime.isInitialized()) {
48+
return;
49+
}
50+
4751
System.loadLibrary("NativeScript");
4852

4953
Logger logger = new LogcatLogger(app);
@@ -117,7 +121,13 @@ public void initRuntime()
117121

118122
runtime.init();
119123
runtime.runScript(new File(appDir, "internal/ts_helpers.js"));
120-
Runtime.initInstance(this.app);
124+
try {
125+
// put this call in a try/catch block because with the latest changes in the modules it is not granted that NativeScriptApplication is extended through JavaScript.
126+
Runtime.initInstance(this.app);
127+
}
128+
catch (Exception e) {
129+
130+
}
121131
runtime.run();
122132
}
123133
}

0 commit comments

Comments
 (0)