javafxport's FxActivity.onBackPressed is not called

290 views Asked by At

I am using javafxports to launch my gradle based javafx application on android. Using jfxmobile-plugin the application is packed into a single apk file and is working fine. In order to override the back pressed behaviour of the FxActivity, I tried to extend this class and add my own Activity class.

public class MyActivity extends FxActivity
{
    @Override
    public void onBackPressed()
    {
        System.out.println("onBackPressed");
        super.onBackPressed();
    }

}

I added the full quialified name of MyActivity class to the AndroidManifest.xml and again the application works fine except for when I press the android's back button, I can not see the message "onBackPressed" to be printed out. There is another message which shows the back button is pressed and handled by some jfxrt.jar class or something. The message looks like this:

my.sample.package.name  I/System.out(16507): KeyEvent: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=144078131, downTime=144078016, deviceId=-1, source=0x101 } with action = 1

Does any one know how to override the onBackPressed in such a way it works? Another question I have is what javafxports exactly does to close the javafx stage on back pressed?

EDIT:

Another question is:

I have two different javafxports android application, name G and B; These two applications have the same build.gradle files except for the dependencies sections. Application G has a few dependencies like

dependencies {
compile 'org.reflections:reflections:0.9.10'
compile 'org.dom4j:dom4j:2.0.0'
compile 'com.jfoenix:jfoenix:1.0.0'
compile 'com.gluonhq:charm:2.1.1'
androidRuntime 'com.gluonhq:charm-android:2.1.1'
}

However application B has a lot of dependencies which are mostly my own subprojects; But B do not depend on these two specific artifacts

 compile 'com.gluonhq:charm:2.1.1'
 androidRuntime 'com.gluonhq:charm-android:2.1.1'

On back pressed, application G exits to android home as expected. However, application B does not react to the back press event on android although a message like the one I mentioned above is printed out on the android's monitor screen.

I want to know why B ignores the back pressed event?

1

There are 1 answers

4
José Pereda On BEST ANSWER

First of all, the Gluon Charm dependencies you are using are quite old. Current version is 4.2.0. I suggest you also update the Gluon IDE plugin to the current 2.5.0 version, as it will generate an up-to-date build.gradle script.

As shown in this question, the Android back button is mapped to the ESCAPE key, and Charm implements a key event listener so we can switch Views or close Layers.

Also Charm implements the Charm Down plugin lifecycle (see this question), and when the current View is the Home View, pressing the Android back button has the effect of finishing the activity/application.

Since you are not using Charm dependencies in B, that won't work unless you implement it.