Page 1 of 1

Backbutton to Minimize/Iconify on Android?

Posted: Mon Nov 20, 2017 11:37 am
by xavimat
A tester has pointed out that, on Android, the backbutton is used not only to go back to the previous "screen" on an app, but also, from the "main screen" of the app, to minimize/iconify it (I don't know the correct word for Android).

On Ren'Py the key "K_AC_BACK" (=Android Backbutton) is mapped to rollback, as it is expected when in dialog, but it does nothing in the main menu.
My tester was expecting it to minimize/iconify the app, and I think he has a point.

My questions:
  • Is renpy.iconify() the correct function for Android? Is it another one? Should it exist?
  • Can it (or other function) be mapped to "K_AC_BACK" with "key" or "keysym"?
  • Should my code (see below) work on Android devices (I'll try to test later).
I'm trying this on the navigation screen, and it's not working on the emulator (not tested on actual devices yet):

Code: Select all

if renpy.variant("touch"):
    key "K_AC_BACK" action Function(renpy.iconify)
A funny thing: I've tried the first time with this code (on the emulator):

Code: Select all

if renpy.variant("touch"):
    key "K_AC_BACK" action renpy.iconify()
And two things happen:
  1. Due to the prediction system, the function is actually executed before pressing anything, and it minimizes/iconifies the window.
  2. When windowed again, the program shows an error: "Action is required in ui.key". The action IS there (is the function) and it's being executed and asked for at the same time.
Anyway, that was my fault for not using the correct "action Function(xxx)".

Re: Backbutton to Minimize/Iconify on Android?

Posted: Mon Nov 27, 2017 6:29 pm
by DragoonHP
* renpy.iconify() doesn't work on actual Android devices, but it will work in the emulator. because renpy.iconify calls pygame.display.iconify. The reason it didn't work for you in the emulator is because as far as I'm aware, there is no way to trigger the AC_BACK on PC.

* I don't see why it couldn't be mapped to anything else;

* Nope, it won't.

Re: Backbutton to Minimize/Iconify on Android?

Posted: Tue Nov 28, 2017 5:39 pm
by xavimat
Thanks, DraggonHP.

I remember now that the Quit() action in Ren'Py has (or had) in Android that result: minimizing.

The point here is, all apps (AFAIK) in Android are minimized when the back button is pressed in their "home" page, except Ren'Py ones, that do nothing when the same button is pressed in the main_menu screen.
I've never have thought about it, but my tester pointed it out immediately. Shouldn't Ren'Py have the same behavior than everyone else?

Maybe with "key" in the current navigation() screen in screens.rpy?

Code: Select all

Change this:
        if renpy.variant("pc"):
            ## ...
            ## The quit button is banned on iOS and unnecessary on Android.
            textbutton _("Quit") action Quit(confirm=not main_menu)

To this:
        if renpy.variant("pc"):
            ## ...
            ## The quit button is banned on iOS and unnecessary on Android.
            textbutton _("Quit") action Quit(confirm=not main_menu)
        else:
            key "K_AC_BACK" action Quit(confirm not main_menu)

Re: Backbutton to Minimize/Iconify on Android?

Posted: Wed Nov 29, 2017 8:28 am
by Errilhl
Well... hardly "all apps" - quite a few games, at least, and definitely some other apps as well, have a "do you want to quit" when clicking back-button from main menu / main screen.

Re: Backbutton to Minimize/Iconify on Android?

Posted: Wed Nov 29, 2017 6:51 pm
by xavimat
Errilhl wrote: Wed Nov 29, 2017 8:28 am Well... hardly "all apps" - quite a few games, at least, and definitely some other apps as well, have a "do you want to quit" when clicking back-button from main menu / main screen.
Yes, my bad. I don't actually play games on android. Again my question is, when those games and apps ask "do you want to quit", and the user touches " yes", how Ren'Py can handle it?
I've tried the "action Quit()" solution and it doesn't seem the right one. It does not quit totally the app, neither it iconifies it. I'm not really sure what it does.
So, it's better for Ren'Py to just ignore the android backbutton on main_menu? There are quite a few ren'py games on google play. If all of them are ignoring this button probably means that it's not a real problem for their players.

Re: Backbutton to Minimize/Iconify on Android?

Posted: Wed Nov 29, 2017 8:19 pm
by Imperf3kt
Using Quit() is working for me just fine on Android and the app is indeed closing, not going into the background. It may be how you are using it.

Re: Backbutton to Minimize/Iconify on Android?

Posted: Sun Dec 03, 2017 5:39 pm
by xavimat
Imperf3kt wrote: Wed Nov 29, 2017 8:19 pm Using Quit() is working for me just fine on Android and the app is indeed closing, not going into the background. It may be how you are using it.
Ok. I was testing it with an older Ren'Py version (an old game I made). I'll test it with the current version. Thanks.

Re: Backbutton to Minimize/Iconify on Android?

Posted: Fri Dec 08, 2017 11:13 am
by ComputerArt.Club
For anyone else trying something similar in their game and testing it on Renpy, I tried something similar in my game and when emulating android with Renpy the back (page up) button did not quit the game, however, when I built the app and installed it on my phone it worked.

There is also a much older thread that discusses something similar but uses alternative code:
viewtopic.php?f=8&t=25226&hilit=android+quit+back

Code: Select all

key "rollback" action Quit(confirm=False)