Skip to content

Commit

Permalink
[TIMOB-25756] Include softRestart
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed Aug 1, 2018
1 parent bfdbf6d commit 91f1cfb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public class AppModule extends KrollModule implements SensorEventListener
private boolean proximityState;
private int proximityEventListenerCount = 0;

private static final String APP_PATH = "Resources/app.js";

public AppModule()
{
super("App");
Expand Down Expand Up @@ -219,23 +217,7 @@ public boolean getAccessibilityEnabled()
@Kroll.method(name = "_restart")
public void restart()
{
KrollRuntime runtime = KrollRuntime.getInstance();

// prevent termination of root activity via TiBaseActivity.shouldFinishRootActivity()
TiBaseActivity.canFinishRoot = false;

// terminate all activities excluding root
TiApplication.terminateActivityStack();

// allow termination again
TiBaseActivity.canFinishRoot = true;

// restart kroll runtime
runtime.doDispose();
runtime.initRuntime();

// manually re-launch app
runtime.doRunModule(KrollAssetHelper.readAsset(APP_PATH), APP_PATH, getActivityProxy());
TiApplication.getInstance().softRestart();
}

@Kroll.method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,28 @@ public void scheduleRestart(int delay)
}
}

public void softRestart()
{
KrollRuntime runtime = KrollRuntime.getInstance();

// prevent termination of root activity via TiBaseActivity.shouldFinishRootActivity()
TiBaseActivity.canFinishRoot = false;

// terminate all activities excluding root
TiApplication.terminateActivityStack();

// allow termination again
TiBaseActivity.canFinishRoot = true;

// restart kroll runtime
runtime.doDispose();
runtime.initRuntime();

// manually re-launch app
runtime.doRunModule(KrollAssetHelper.readAsset(TiC.PATH_APP_JS), TiC.URL_APP_JS,
((TiBaseActivity) getRootOrCurrentActivity()).getActivityProxy());
}

public boolean isRestartPending()
{
return restartPending;
Expand Down Expand Up @@ -814,7 +836,7 @@ private void startLocaleMonitor()
@Override
public void onReceive(Context context, Intent intent)
{
TiApplication.getInstance().scheduleRestart(0);
TiApplication.getInstance().softRestart();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3478,4 +3478,5 @@ public class TiC
public static final String URL_APP_SCHEME = "app";
public static final String URL_APP_JS = "app://app.js";
public static final String URL_ANDROID_ASSET_RESOURCES = "file:///android_asset/Resources/";
public static final String PATH_APP_JS = "Resources/app.js";
}

0 comments on commit 91f1cfb

Please sign in to comment.