javafxports 8.60.7 - 在Android上使用Back按钮 - 无退出应用程序 [英] javafxports 8.60.7 - using Back button on Android - none exit application

查看:332
本文介绍了javafxports 8.60.7 - 在Android上使用Back按钮 - 无退出应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅使用javafxports 8.60.7 for Android(不使用Gluon Mobile) - 当您按返回按钮时,应用程序将不会退出。
如何解决此问题?

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?

推荐答案

虽然JavaFXPorts允许您在Android上运行普通JavaFX,但有一些平台功能不是由OpenJFX项目实现的,比如你提到的后退按钮。

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在视图和图层中正确处理后退按钮,但如果你不使用它,你将不得不照顾它。

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.

问题已经有了如何处理Android上的Back按钮的答案。

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

编辑

至于退出部分,Charm Down OSS 库已经提供了关闭应用程序的服务。它可以通过添加Lifecycle插件轻松地包含在您的项目中:

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'
    }
}

当你想通过后退按钮完成你的应用程序时,现在只需要调用 shutdown

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);

在幕后,这将检查平台,并调用 Platform.exit桌面上的()或Android上的 FXActivity.getInstance()。finish()

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

这篇关于javafxports 8.60.7 - 在Android上使用Back按钮 - 无退出应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆