-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-25886] Refactor Ti.App._restart() #9946
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,10 @@ | |
import org.appcelerator.kroll.KrollRuntime; | ||
import org.appcelerator.kroll.annotations.Kroll; | ||
import org.appcelerator.kroll.common.Log; | ||
import org.appcelerator.kroll.util.KrollAssetHelper; | ||
import org.appcelerator.titanium.ITiAppInfo; | ||
import org.appcelerator.titanium.TiApplication; | ||
import org.appcelerator.titanium.TiBaseActivity; | ||
import org.appcelerator.titanium.TiC; | ||
import org.appcelerator.titanium.util.TiConvert; | ||
import org.appcelerator.titanium.util.TiPlatformHelper; | ||
|
@@ -50,6 +52,8 @@ 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"); | ||
|
@@ -213,14 +217,23 @@ public boolean getAccessibilityEnabled() | |
@Kroll.method(name = "_restart") | ||
public void restart() | ||
{ | ||
Application app = (Application) KrollRuntime.getInstance().getKrollApplication(); | ||
Intent i = app.getPackageManager().getLaunchIntentForPackage(app.getPackageName()); | ||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | ||
i.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); | ||
i.addCategory(Intent.CATEGORY_LAUNCHER); | ||
i.setAction(Intent.ACTION_MAIN); | ||
KrollRuntime runtime = KrollRuntime.getInstance(); | ||
|
||
// prevent termination of root activity via TiBaseActivity.shouldFinishRootActivity() | ||
TiBaseActivity.canFinishRoot = false; | ||
|
||
// terminate all activities excluding root | ||
TiApplication.terminateActivityStack(); | ||
app.startActivity(i); | ||
|
||
// 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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes, I'll test these changes with an Alloy app There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update, works fine with Alloy apps |
||
} | ||
|
||
@Kroll.method | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we set
canFinishRoot
tofalse
, then backing out of the first Ti.UI.Window in a restarted window will now show the launcher activity, right? We may need to resetcanFinishRoot
back totrue
after the restart.Perhaps this shouldn't be an exposed public global and handle it via a method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
canFinishRoot
returns to true on Line 229