0

I'm wondering if it's possible to manually edit the current navigation item index in Crosswalk (https://crosswalk-project.org/apis/embeddingapidocs_v3/org/xwalk/core/XWalkNavigationHistory.html#getCurrentIndex())?

The reason I need to do this is because when we try to go back in our application the second time starting it the index is 0 when it should be 1 and hence destroying the application.

We use window.navigator in our website to register what the user does.

jwanglof
  • 548
  • 1
  • 5
  • 20

1 Answers1

0

I managed to fix it by pushing an empty state to the website. Relevant code:

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            if (mXWalkView != null && 
                    SyncBackgroundService.APP_IS_RUNNING && 
                    mXWalkView.getNavigationHistory().getCurrentIndex() == 0) {
                Crashlytics.log(Log.DEBUG, LOG_TAG, "Third");
                mXWalkView.evaluateJavascript("history.pushState({}, \"\", \"\");", null);
                return true;
            } else {
                return super.dispatchKeyEvent(event);
            }
    }
}

So what is basically does is that if the application is running and the current index is 0 it will push a new navigate state to the website so it doesn't destroy or pause the application.

jwanglof
  • 548
  • 1
  • 5
  • 20