1010import android .util .Log ;
1111import 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,18 +34,19 @@ public boolean hasErrorIntent() {
3834 return hasErrorIntent ;
3935 }
4036
41- public void initRuntime ()
37+ public static Runtime initRuntime (Application app )
4238 {
4339 if (Runtime .isInitialized ()) {
44- return ;
40+ return Runtime . getCurrentRuntime () ;
4541 }
4642
4743 System .loadLibrary ("NativeScript" );
4844
45+ Runtime runtime = null ;
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
52- boolean showErrorIntent = hasErrorIntent ();
49+ boolean showErrorIntent = hasErrorIntent (app );
5350 if (!showErrorIntent ) {
5451 NativeScriptUncaughtExceptionHandler exHandler = new NativeScriptUncaughtExceptionHandler (logger , app );
5552
@@ -110,12 +107,12 @@ public void initRuntime()
110107 ThreadScheduler workThreadScheduler = new WorkThreadScheduler (new Handler (Looper .getMainLooper ()));
111108 Configuration config = new Configuration (workThreadScheduler , logger , debugger , appName , null , rootDir ,
112109 appDir , classLoader , dexDir , dexThumb , v8Config );
113- Runtime runtime = new Runtime (config );
110+ runtime = new Runtime (config );
114111
115112 exHandler .setRuntime (runtime );
116113
117- if (NativeScriptSyncService .isSyncEnabled (this . app )) {
118- NativeScriptSyncService syncService = new NativeScriptSyncService (runtime , logger , this . app );
114+ if (NativeScriptSyncService .isSyncEnabled (app )) {
115+ NativeScriptSyncService syncService = new NativeScriptSyncService (runtime , logger , app );
119116
120117 syncService .sync ();
121118 syncService .startServer ();
@@ -141,14 +138,14 @@ public void initRuntime()
141138
142139 try {
143140 // 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.
144- Runtime .initInstance (this . app );
141+ Runtime .initInstance (app );
145142 }
146143 catch (Exception e ) {
147144
148145 }
149- runtime .run ();
150146 }
147+ return runtime ;
151148 }
152149
153- private final String logTag = "MyApp" ;
150+ private static final String logTag = "MyApp" ;
154151}
0 commit comments