Backbutton to Minimize/Iconify on Android?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Backbutton to Minimize/Iconify on Android?

#1 Post 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)".
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: Backbutton to Minimize/Iconify on Android?

#2 Post 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.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: Backbutton to Minimize/Iconify on Android?

#3 Post 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)
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Errilhl
Regular
Posts: 164
Joined: Wed Nov 08, 2017 4:32 pm
Projects: HSS
Deviantart: studioerrilhl
Github: studioerrilhl
Contact:

Re: Backbutton to Minimize/Iconify on Android?

#4 Post 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.
Currently working on: Image

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: Backbutton to Minimize/Iconify on Android?

#5 Post 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.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Backbutton to Minimize/Iconify on Android?

#6 Post 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.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: Backbutton to Minimize/Iconify on Android?

#7 Post 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.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
ComputerArt.Club
Veteran
Posts: 427
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

Re: Backbutton to Minimize/Iconify on Android?

#8 Post 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)

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]