javafxports 8.60.7 - using Back button on Android - none exit application

走远了吗. 提交于 2019-12-25 07:17:43

问题


Using only javafxports 8.60.7 for Android (without Gluon Mobile) - when you press the Back button, the application will not exit. How can I fix this?


回答1:


While JavaFXPorts allows you running plain JavaFX on Android, there are some platform features not implemented by the OpenJFX project, like the back button you mention.

Gluon Mobile deals properly with the back button both in Views and Layers, but if you are not using it, you will have to take care of it.

This question already has an answer on how to deal with the Back button on Android.

Edit

As for the "exit" part, the Charm Down OSS library already provides a service to shutdown the application. It can be easily included on your project by adding the Lifecycle plugin:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.1.0'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
    jcenter()
}

mainClassName = '<your.main.class>'

jfxmobile {
    downConfig {
        version '3.0.0'
        plugins 'lifecycle'
    }
    android {
        manifest = 'src/android/AndroidManifest.xml'
    }
}

And now all you need it calling shutdown when you want to finish your application via the back button:

Services.get(LifecycleService.class).ifPresent(LifecycleService::shutdown);

Under the hood, this will check the platform, and call Platform.exit() on Desktop or FXActivity.getInstance().finish() on Android.



来源:https://stackoverflow.com/questions/40214212/javafxports-8-60-7-using-back-button-on-android-none-exit-application

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