Skip to content

Commit ffc5a2e

Browse files
author
Mihail Slavchev
committed
Use static method initRuntime instead of instance one
1 parent 85ffb08 commit ffc5a2e

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

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

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

1313
public void onCreate() {
1414
super.onCreate();
15-
com.tns.Runtime runtime = new RuntimeHelper(this).initRuntime();
15+
com.tns.Runtime runtime = RuntimeHelper.initRuntime(this);
1616
if (runtime !=null) {
1717
runtime.run();
1818
}

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,12 @@
1010
import android.util.Log;
1111
import java.io.IOException;
1212

13-
public class RuntimeHelper {
14-
private final Application app;
15-
16-
public RuntimeHelper(Application app) {
17-
this.app = app;
18-
}
13+
public final class RuntimeHelper {
14+
private RuntimeHelper() {}
1915

2016
// hasErrorIntent tells you if there was an event (with an uncaught
2117
// exception) raised from ErrorReport
22-
public boolean hasErrorIntent() {
18+
public static boolean hasErrorIntent(Application app) {
2319
boolean hasErrorIntent = false;
2420

2521
try {
@@ -38,7 +34,7 @@ public boolean hasErrorIntent() {
3834
return hasErrorIntent;
3935
}
4036

41-
public Runtime initRuntime()
37+
public static Runtime initRuntime(Application app)
4238
{
4339
if (Runtime.isInitialized()) {
4440
return Runtime.getCurrentRuntime();
@@ -48,9 +44,9 @@ public Runtime initRuntime()
4844

4945
Runtime runtime = null;
5046
Logger logger = new LogcatLogger(app);
51-
Debugger debugger = AndroidJsDebugger.isDebuggableApp(this.app) ? new AndroidJsDebugger(app, logger) : null;
47+
Debugger debugger = AndroidJsDebugger.isDebuggableApp(app) ? new AndroidJsDebugger(app, logger) : null;
5248

53-
boolean showErrorIntent = hasErrorIntent();
49+
boolean showErrorIntent = hasErrorIntent(app);
5450
if (!showErrorIntent) {
5551
NativeScriptUncaughtExceptionHandler exHandler = new NativeScriptUncaughtExceptionHandler(logger, app);
5652

@@ -115,8 +111,8 @@ public Runtime initRuntime()
115111

116112
exHandler.setRuntime(runtime);
117113

118-
if (NativeScriptSyncService.isSyncEnabled(this.app)) {
119-
NativeScriptSyncService syncService = new NativeScriptSyncService(runtime, logger, this.app);
114+
if (NativeScriptSyncService.isSyncEnabled(app)) {
115+
NativeScriptSyncService syncService = new NativeScriptSyncService(runtime, logger, app);
120116

121117
syncService.sync();
122118
syncService.startServer();
@@ -142,7 +138,7 @@ public Runtime initRuntime()
142138

143139
try {
144140
// 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.
145-
Runtime.initInstance(this.app);
141+
Runtime.initInstance(app);
146142
}
147143
catch (Exception e) {
148144

@@ -151,5 +147,5 @@ public Runtime initRuntime()
151147
return runtime;
152148
}
153149

154-
private final String logTag = "MyApp";
150+
private static final String logTag = "MyApp";
155151
}

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

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

1313
public void onCreate() {
1414
super.onCreate();
15-
com.tns.Runtime runtime = new RuntimeHelper(this).initRuntime();
15+
com.tns.Runtime runtime = RuntimeHelper.initRuntime(this);
1616
if (runtime !=null) {
1717
runtime.run();
1818
}

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
import android.util.Log;
1111
import java.io.IOException;
1212

13-
public class RuntimeHelper {
14-
private final Application app;
15-
16-
public RuntimeHelper(Application app) {
17-
this.app = app;
13+
public final class RuntimeHelper {
14+
private RuntimeHelper() {
1815
}
1916

2017
// hasErrorIntent tells you if there was an event (with an uncaught
2118
// exception) raised from ErrorReport
22-
public boolean hasErrorIntent() {
19+
private static boolean hasErrorIntent(Application app) {
2320
boolean hasErrorIntent = false;
2421

2522
try {
@@ -38,7 +35,7 @@ public boolean hasErrorIntent() {
3835
return hasErrorIntent;
3936
}
4037

41-
public Runtime initRuntime()
38+
public static Runtime initRuntime(Application app)
4239
{
4340
if (Runtime.isInitialized()) {
4441
return Runtime.getCurrentRuntime();
@@ -47,10 +44,10 @@ public Runtime initRuntime()
4744
System.loadLibrary("NativeScript");
4845

4946
Logger logger = new LogcatLogger(app);
50-
Debugger debugger = AndroidJsDebugger.isDebuggableApp(this.app) ? new AndroidJsDebugger(app, logger) : null;
47+
Debugger debugger = AndroidJsDebugger.isDebuggableApp(app) ? new AndroidJsDebugger(app, logger) : null;
5148

5249
Runtime runtime = null;
53-
boolean showErrorIntent = hasErrorIntent();
50+
boolean showErrorIntent = hasErrorIntent(app);
5451
if (!showErrorIntent) {
5552
NativeScriptUncaughtExceptionHandler exHandler = new NativeScriptUncaughtExceptionHandler(logger, app);
5653

@@ -115,8 +112,8 @@ public Runtime initRuntime()
115112

116113
exHandler.setRuntime(runtime);
117114

118-
if (NativeScriptSyncService.isSyncEnabled(this.app)) {
119-
NativeScriptSyncService syncService = new NativeScriptSyncService(runtime, logger, this.app);
115+
if (NativeScriptSyncService.isSyncEnabled(app)) {
116+
NativeScriptSyncService syncService = new NativeScriptSyncService(runtime, logger, app);
120117

121118
syncService.sync();
122119
syncService.startServer();
@@ -142,7 +139,7 @@ public Runtime initRuntime()
142139

143140
try {
144141
// 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.
145-
Runtime.initInstance(this.app);
142+
Runtime.initInstance(app);
146143
}
147144
catch (Exception e) {
148145

@@ -151,5 +148,5 @@ public Runtime initRuntime()
151148
return runtime;
152149
}
153150

154-
private final String logTag = "MyApp";
151+
private static final String logTag = "MyApp";
155152
}

0 commit comments

Comments
 (0)