问题
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