How to detect the back button action on mobile?

I see various threads on this, but nothing explaining the actual code used to capture the back button event. I tried comparing action_id to KEY_BACK and I tried creating a binding for the “Back” key in the input file. Neither method seems to respond to the back button. Does anyone know the proper way to do this?

We have received reports that the back button behavior has changed on Android after the recent change where the engine is now running on a separate thread. In previous versions KEY_BACK events were generated and could be captured by the game.

Do you know of a way to clear logcat defold logs or perhaps watch the debug messages live while the app is running? I tried “adb logcat -s defold” but I have so many logs the command never returns (even if I leave it running for hours.)

EDIT: I setup dmengine.apk to debug it. I don’t see any specific action_id or action properties that indicate that the back button is hit, just hash: [touch] and nil events… Wondering if it’s not possible to detect this for certain devices, etc with the current version of Defold?

EDIT2: Hmm, I think the action is captured, but even though my game saves on back button when I re-open it I get a black screen unless I manually kill the app and start it again. Also, it doesn’t seem to actually save if I exit this way… Not sure what’s going on =/

1 Like
adb logcat -c

https://developer.android.com/studio/command-line/logcat

I can also recommend using PID Cat, a wrapper around logcat, to help with filtering and to show logs with color. https://github.com/JakeWharton/pidcat

1 Like

Hmm yeah I tried that. I think it did clear my logs but it takes an extremely long time to run adb logcat -s even though there are no logs now. Thanks for the advice, I’ll see if I can set that up maybe it will work better :stuck_out_tongue:

That doesn’t clear the logs, only print them out as they come.

Also I’d suggest not using “-s defold” unless that’s what you want, since it doesn’t print out all info from the device (e.g from google related services).

I personally use android-deploy.sh to launch apps and instead dig out the PID (process ID) to log all services under that PID.

1 Like

I think this is what PID Cat does + color logging

Correct, and here’s my personal android_deploy.sh with support for pidcat

2 Likes

Hello @britzl

What’s the status of Back Button on Mobile?

I’m trying it on Android S9 Galaxy, it’s not responding. Could you please inform me if it’s under investigation? Can I hope for a fix soon?

Thanks a lot

Regards
Riad

Hmm, I’ve just tested it on 3 phones and it works fine. Are you sure you added KEY_BACK in input bindings?

1 Like

Yes, we are not aware of any problems detecting the back button.

1 Like

Hello,

@AGulev , I have added KEY_BACK as it should be…

After several tests I realized that it works only when I try the back button several times… which is weird, it’s like there is sensitive parameter applied to it, and I have to insist to make it work!

My back button works normally with other apps. Any idea what am I doing wrong?

Thanks and regards
Riad

What kind of phone do you have?

Hello,
It’s Samsung S9. I will try another brand and let you know asap.
BR/Riad