Skip to content
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

Merged
merged 4 commits into from May 24, 2018

Conversation

garymathews
Copy link
Contributor

@garymathews garymathews commented Mar 19, 2018

  • Improve Ti.App._restart() performance
NOTES
  • Need to test with native Titanium modules Works
  • No tests as it restarts the context
TEST CASE
var win = Ti.UI.createWindow({ backgroundColor: 'gray', layout: 'vertical' }),
    globalBtn = Ti.UI.createButton({ title: 'CHECK GLOBAL (always undefined)' }),
    restartBtn = Ti.UI.createButton({ title: 'RESTART' });

globalBtn.addEventListener('click', function () {
    alert(JSON.stringify(global.TEST));
});

restartBtn.addEventListener('click', function () {
    global.TEST = true;
    Ti.App._restart();
});

setTimeout(() => {
    win.backgroundColor = 'green';
}, 3000);

win.add([ globalBtn, restartBtn ]);
win.open();

JIRA Ticket

@build
Copy link
Contributor

build commented Mar 19, 2018

Messages
📖

💾 Here's the generated SDK zipfile.

Generated by 🚫 dangerJS

runtime.initRuntime();

// manually re-launch app
runtime.doRunModule(KrollAssetHelper.readAsset(APP_PATH), APP_PATH, getActivityProxy());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our TiLaunchActivity.loadActivityScript() and the resolveUrl() method it calls does some extra logic when loading a JavaScript on startup. Particularly with Alloy. We might need to do a code shift.
https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/TiLaunchActivity.java#L120

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I'll test these changes with an Alloy app

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update, works fine with Alloy apps

KrollRuntime runtime = KrollRuntime.getInstance();

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we set canFinishRoot to false, then backing out of the first Ti.UI.Window in a restarted window will now show the launcher activity, right? We may need to reset canFinishRoot back to true after the restart.

Perhaps this shouldn't be an exposed public global and handle it via a method.

Copy link
Contributor Author

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

@sgtcoolguy
Copy link
Contributor

@jquick-axway ping

@build build added the android label Apr 23, 2018
@sgtcoolguy sgtcoolguy modified the milestones: 7.2.0, 7.3.0 May 16, 2018
@sgtcoolguy sgtcoolguy merged commit 3f30ded into tidev:master May 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants