Start specific view of Gluon App from a notification

有些话、适合烂在心里 提交于 2021-01-29 01:41:11

问题


I set up an alarm to show a corresponding Notification. The PendingIntent of the Notification is used to start the Gluon App main class. To show a View other than the homeView, I call switchView(otherView) in the postInit method. OtherView is shown, but without AppBar. While it's possible to make the AppBar appear, I wonder if this is the right approach.

@Override
public void postInit(Scene scene) {
    // additional setUp logic

    boolean showReadingView = (boolean) PlatformProvider.getPlatform().getLaunchIntentExtra("showReadingView", false);
    if (showReadingView) {
        switchView(READING_VIEW);
    }
}

回答1:


When triggering anything related to the JavaFX thread from another thread, we have to use Platform.runLater().

Yours is a clear case of this situation: the Android thread is calling some pending intent, and as a result, the app is started again.

This should be done:

@Override
public void postInit(Scene scene) {
    // additional setUp logic

    boolean showReadingView = (boolean) PlatformProvider.getPlatform().getLaunchIntentExtra("showReadingView", false);
    if (showReadingView) {
        Platform.runLater(() -> switchView(READING_VIEW));
    }
}


来源:https://stackoverflow.com/questions/37912175/start-specific-view-of-gluon-app-from-a-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!