0
仅适用于Android的javafxports 8.60.7(不含Gluon Mobile) - 当您按下后退按钮时,应用程序不会退出。 我该如何解决这个问题?javafxports 8.60.7 - 在Android上使用后退按钮 - 无退出应用程序
仅适用于Android的javafxports 8.60.7(不含Gluon Mobile) - 当您按下后退按钮时,应用程序不会退出。 我该如何解决这个问题?javafxports 8.60.7 - 在Android上使用后退按钮 - 无退出应用程序
尽管JavaFXPorts允许您在Android上运行普通的JavaFX,但OpenJFX项目并没有实现一些平台功能,例如您提到的后退按钮。
Gluon Mobile可以正常处理视图和图层中的后退按钮,但是如果您不使用它,您将不得不照顾它。
这question已经有一个关于如何处理Android上的后退按钮的答案。
编辑
至于“退出”的一部分,魅力向下OSS库中已经提供了关机服务的应用程序。它可以通过添加生命周期插件可以很容易地纳入您的项目:
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'
}
}
而现在你只需要在调用shutdown
当你想通过后退按钮来完成您的应用程序:
Services.get(LifecycleService.class).ifPresent(LifecycleService::shutdown);
下这将检查平台,并在桌面上拨打Platform.exit()
或在Android上拨打FXActivity.getInstance().finish()
。
是的,我的问题已经有answeras你说过,但只是补充说,Android需要调用FXActivity.getInstance()。finish(); –
要使用javafxports最好使用JoséPereda的源代码:https://github.com/jperedadnr/Game2048FX –
再次感谢JoséPereda。 –