Skip to content

Commit 85ffb08

Browse files
author
Mihail Slavchev
committed
Update project template in order to execute Runtime.run() method at the end of Application.onCreate() method
1 parent c5b6a9f commit 85ffb08

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed
90 Bytes
Binary file not shown.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ public NativeScriptApplication() {
1212

1313
public void onCreate() {
1414
super.onCreate();
15-
new RuntimeHelper(this).initRuntime();
15+
com.tns.Runtime runtime = new RuntimeHelper(this).initRuntime();
16+
if (runtime !=null) {
17+
runtime.run();
18+
}
1619
}
1720

1821
public static Application getInstance() {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ public boolean hasErrorIntent() {
3838
return hasErrorIntent;
3939
}
4040

41-
public void initRuntime()
41+
public Runtime initRuntime()
4242
{
4343
if (Runtime.isInitialized()) {
44-
return;
44+
return Runtime.getCurrentRuntime();
4545
}
4646

4747
System.loadLibrary("NativeScript");
4848

49+
Runtime runtime = null;
4950
Logger logger = new LogcatLogger(app);
5051
Debugger debugger = AndroidJsDebugger.isDebuggableApp(this.app) ? new AndroidJsDebugger(app, logger) : null;
5152

@@ -110,7 +111,7 @@ public void initRuntime()
110111
ThreadScheduler workThreadScheduler = new WorkThreadScheduler(new Handler(Looper.getMainLooper()));
111112
Configuration config = new Configuration(workThreadScheduler, logger, debugger, appName, null, rootDir,
112113
appDir, classLoader, dexDir, dexThumb, v8Config);
113-
Runtime runtime = new Runtime(config);
114+
runtime = new Runtime(config);
114115

115116
exHandler.setRuntime(runtime);
116117

@@ -146,8 +147,8 @@ public void initRuntime()
146147
catch (Exception e) {
147148

148149
}
149-
runtime.run();
150150
}
151+
return runtime;
151152
}
152153

153154
private final String logTag = "MyApp";

runtime/src/main/java/com/tns/Runtime.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public int getRuntimeId()
122122
return this.runtimeId;
123123
}
124124

125-
private static Runtime getCurrentRuntime()
125+
public static Runtime getCurrentRuntime()
126126
{
127127
Runtime runtime = currentRuntime.get();
128128

test-app/app/src/main/java/com/tns/NativeScriptApplication.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ public NativeScriptApplication() {
1212

1313
public void onCreate() {
1414
super.onCreate();
15-
new RuntimeHelper(this).initRuntime();
15+
com.tns.Runtime runtime = new RuntimeHelper(this).initRuntime();
16+
if (runtime !=null) {
17+
runtime.run();
18+
}
1619
}
1720

1821
public static Application getInstance() {

test-app/app/src/main/java/com/tns/RuntimeHelper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@ public boolean hasErrorIntent() {
3838
return hasErrorIntent;
3939
}
4040

41-
public void initRuntime()
41+
public Runtime initRuntime()
4242
{
4343
if (Runtime.isInitialized()) {
44-
return;
44+
return Runtime.getCurrentRuntime();
4545
}
4646

4747
System.loadLibrary("NativeScript");
4848

4949
Logger logger = new LogcatLogger(app);
5050
Debugger debugger = AndroidJsDebugger.isDebuggableApp(this.app) ? new AndroidJsDebugger(app, logger) : null;
5151

52+
Runtime runtime = null;
5253
boolean showErrorIntent = hasErrorIntent();
5354
if (!showErrorIntent) {
5455
NativeScriptUncaughtExceptionHandler exHandler = new NativeScriptUncaughtExceptionHandler(logger, app);
@@ -110,7 +111,7 @@ public void initRuntime()
110111
ThreadScheduler workThreadScheduler = new WorkThreadScheduler(new Handler(Looper.getMainLooper()));
111112
Configuration config = new Configuration(workThreadScheduler, logger, debugger, appName, null, rootDir,
112113
appDir, classLoader, dexDir, dexThumb, v8Config);
113-
Runtime runtime = new Runtime(config);
114+
runtime = new Runtime(config);
114115

115116
exHandler.setRuntime(runtime);
116117

@@ -146,8 +147,8 @@ public void initRuntime()
146147
catch (Exception e) {
147148

148149
}
149-
runtime.run();
150150
}
151+
return runtime;
151152
}
152153

153154
private final String logTag = "MyApp";

0 commit comments

Comments
 (0)