Android game_end() function not working

3jgamesdev

Member
Hi good day,

I was using the latest version of GM 1.4.1788 in the last update game_end() function works fine but now it wont close my game in my mobile devices,i read the updates it seems it will not work anymore?, is there any way to make my game exit when user want to close it?

Thanks in advance
 

zbox

Member
GMC Elder
Mobile games don't usually allow you to do this sort of thing (strictly forbidden on iOS and an anti-pattern on android), I'll say though I have actually uses game_end() legitimately a few times for when the user presses the "Back" key enough times on a menu to close the game. I don't any more though because it actually killed the process, I use an extension to "minimize" the game in that sort of scenario rather than killing it completely.
 
G

Guest User

Guest
Anyone here know how to completely fix the issue with android quit event?
 
G

Guest User

Guest
See above post?
The link doesn't work. I'm really interesting in getting the android quit game session to work. I am releasing my game out this week. Its free to download.
 
W

Wraithious

Guest
The link doesn't work. I'm really interesting in getting the android quit game session to work. I am releasing my game out this week. Its free to download.
Yea that link defiantly doesn't work, but game_end() defiantly does work in android, where are you calling it from? I suggest using either the drag and drop key press event for the back button or the equivalent keyboard function in the step or alarm event and put the function there, it will work.
and as someone mentioned, it will kill the game process so the user won't be able to use the home button to restart the game, but seriously when you want to end the game you don't want it running in the background burning up the player's battery so I think it's the best solution. and also tho, Android and google play are trying to get devs to stop using the back key to end games and that's pretty lame if you ask me, that's the way it always was and always worked perfectly fine to make sure your game ends when you want it to end!
 

zbox

Member
GMC Elder
Well.. the link doesn't work because the marketplace has been down for a few hours but when it isn't down it will work which hopefully will be soon
 

RangerX

Member
You can't close your game on IOS and Android. Its a requirement from the platforms holders themselves, a programming guideline that is part of their development liscencing.
This is why "game_end()" won't work and its not a bug, its the platforms that are asking for this. On mobile when you game ends it doesn't because it stays available in a "recent app" list. Then there's an OS function that truly closes your game when you swipe it from the "recent app list".
 

zbox

Member
GMC Elder
You can't close your game on IOS and Android. Its a requirement from the platforms holders themselves, a programming guideline that is part of their development liscencing.
This is why "game_end()" won't work and its not a bug, its the platforms that are asking for this. On mobile when you game ends it doesn't because it stays available in a "recent app" list. Then there's an OS function that truly closes your game when you swipe it from the "recent app list".
It may be true for iOS and a guideline for Android - But you can actually implement on android legitimately so that with a function call a) the app closes and/or b ) the app is removed from the recents list. I know because it is an extension I've developed for someone recently :)
 
W

Wraithious

Guest
You can't close your game on IOS and Android. Its a requirement from the platforms holders themselves, a programming guideline that is part of their development liscencing.
This is why "game_end()" won't work and its not a bug, its the platforms that are asking for this. On mobile when you game ends it doesn't because it stays available in a "recent app" list. Then there's an OS function that truly closes your game when you swipe it from the "recent app list".
Do you have a link about that? I do remember reading somewhere about it but now I can't find it, but I did find this on the google developer site which has no problem with the back button exiting your app to the home screen or even exiting to another app so now I'm really confused about this
Navigation with Back and Up
DEVELOPER DOCS
Implementing Effective Navigation

Consistent navigation is an essential component of the overall user experience. Few things frustrate users more than basic navigation that behaves in inconsistent and unexpected ways. Thoughtfully following the guidelines for Back and Up will make your app's navigation predictable and reliable for your users.

Action bars provide a second, standard navigation mechanism: the Up button, consisting of the app icon and a left-point caret.


Up vs. Back
The Up button is used to navigate within an app based on the hierarchical relationships between screens. For instance, if screen A displays a list of items, and selecting an item leads to screen B (which presents that item in more detail), then screen B should offer an Up button that returns to screen A.

If a screen is the topmost one in an app (that is, the app's home), it should not present an Up button.

The system Back button is used to navigate, in reverse chronological order, through the history of screens the user has recently worked with. It is generally based on the temporal relationships between screens, rather than the app's hierarchy.

When the previously viewed screen is also the hierarchical parent of the current screen, pressing the Back button has the same result as pressing an Up button—this is a common occurrence. However, unlike the Up button, which ensures the user remains within your app, the Back button can return the user to the Home screen, or even to a different app.
 
H

HW.

Guest
Actually game_end() never gives an error at all for me on Android, yeah i don't talk about iOS.

And top AAA devs on android are using it. (real exit not spawn on recent list) The game end before 1788 also worked like that actually.

I read iOS forbids it, but Google never forbids it on Android. Only "suggests" or "recommends" it, which it can still be done (real exit without ever spawn on the recent list) using runtime before the 2.1.4 or before 1788. The pattern is still widely implemented by many android game developers in fact. Just install some of the popular Android games developed by top AAA devs, and you will see that their exit isn't sending to background, but purely ending the whole task, the same as we do it using the game_end before 1788 and 2.1.3 down.

BUT, with the latest solution from YoYo, as of 2.1.4 the game_end on Android will now "send the app to the background" which i think is the best solution instead of just nothing a.k.a. ignoring it like on iOS. Android is not iOS, okay! :p so i am glad at least there is a solution, finally.

http://gms.yoyogames.com/release-notes-runtime.html

SO, if you use GMS2, you do not need any extension in fact. Just use the built in game_end with the latest runner of 2.1.4.

Although i prefer a real exit app which has been working on previous versions (Android), i can now accept the latest solution which is per Google recommendation.

Cheers.

PS. i don't install 2.1.4 yet, but the data is from the release notes, and SOON i will also install it and implement all my games with the "new" game_end function and let's see what are the responses of the players, i hope i don't need to use the 2.1.3 runner to revert the pattern if there are complaints.
 

RangerX

Member
There you go, that's what I meant.
Your game does not "close" now with "game_end()" because its against the platforms' rules. Its put in the background, what I called earlier the "recent app list".
 
I

icuurd12b42

Guest
Edit: misread
Yeah, that's an unfortunate comma position, should be a semicolon there...

Game End
Similar to the above mentioned Game Start event, this event is only triggered once in the whole game and that is just before the game window actually closes. Again, for an instance with this event to actually do anything it has to be in the room as the game is closed. Please note that this event in really only viable for Windows<;> Ubuntu (Linux) and MacOS games as mobile devices may just close the game without giving GameMaker: Studio the chance to call this event. For browser games made with the HTML5 module, this event should work when the game tab or browser is closed, but not all browsers support this feature (Firefox, Chrome and Safari do at the time of writing) so care must be taken when using it. Typically you would use this event to save data.
 
M

mootaz azaiez

Guest
What about the Game_end Event ! it does not work anymore ! and i really need to optimise the game and delete unnecessary files !
 

Maximiliano

Member
I read iOS forbids it, but Google never forbids it on Android. Only "suggests" or "recommends" it, which it can still be done (real exit without ever spawn on the recent list) using runtime before the 2.1.4 or before 1788. The pattern is still widely implemented by many android game developers in fact. Just install some of the popular Android games developed by top AAA devs, and you will see that their exit isn't sending to background, but purely ending the whole task, the same as we do it using the game_end before 1788 and 2.1.3 down.
I was using it before 1788 and it worked just fine. The app wouldn't close, it was sent to the background. Ever since updating it stopped working. Do you know if this is a bug they plan to fix or is it gone forever? In the release notes it only says that they removed it because it was causing crashes but it doesn't specify if it will be fixed.
 
J

jackhigh24

Guest
this thread is getting confusing, some are talking about game end function and some are talking about game end event, some are saying its change behaviour, some are saying its been taken out for coursing crashes, someone in the know needs to add all the info pertaining to both event and function then close the thread.
 

zbox

Member
GMC Elder
this thread is getting confusing, some are talking about game end function and some are talking about game end event, some are saying its change behaviour, some are saying its been taken out for coursing crashes, someone in the know needs to add all the info pertaining to both event and function then close the thread.
Game end event only works on windows
Game end function works on windows and Android and whether it works on iOS is irrelevant because they won't allow it on the app store

Easy!
 

zbox

Member
GMC Elder
From the manual:
Game End
Similar to the above mentioned Game Start event, this event is only triggered once in the whole game and that is just before the game window actually closes. Again, for an instance with this event to actually do anything it has to be in the room as the game is closed. Please note that this event in really only viable for Windows, Ubuntu (Linux) and MacOS games as mobile devices may just close the game without giving GameMaker: Studio the chance to call this event. For browser games made with the HTML5 module, this event should work when the game tab or browser is closed, but not all browsers support this feature (Firefox, Chrome and Safari do at the time of writing) so care must be taken when using it. Typically you would use this event to save data.
 
I

icuurd12b42

Guest
That's not correct, Rookie. It stopped working once GMS:1.4 second to last update arrived.
Respect your elders or gtfo. Not calling you a liar but since you started this convo that way I dont give a flying eff. I think you are lying.

and your original post
>I have apks for android that use the quit game event to quit the game session. It was never a windows only thing.
I think you confused event with function there

upload_2018-4-9_22-39-33.png
 
E

evenprimes

Guest
If I understand correctly, the 'send to back' behavior for the game_end() function was only introduced for GMS 2. In GMS 1.4, it sounds like the function now does nothing on mobile platforms:
Changed game_end() to be ignored on Android and iOS, following crash logs that indicated this was causing memory corruption and crashes in subsequent runs of your app
Source: https://www.yoyogames.com/downloads/gm-studio/release-notes-studio.html
(Sorry if this was obvious to everyone else--I was getting confused with all the discussion of different versions.)

This is the Wrong Way(tm) to do things for app releases, but just for development purposes, you could make an extension to kill your Android app using this Java code:
Code:
package ${YYAndroidPackageName};

import android.util.Log;
import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.String;

import ${YYAndroidPackageName}.R;
import com.yoyogames.runner.RunnerJNILib;
import ${YYAndroidPackageName}.RunnerActivity;

public class AppCloser {

    public double terminate_app(){
        RunnerJNILib.ExitApplication();
        return 0.0;
    }

}

You might be able to implement send-to-back in 1.4 with a call like
Code:
RunnerActivity.CurrentActivity.moveTaskToBack();
 

zbox

Member
GMC Elder
My god this is a very confused thread haha - If you need to close your game, which is indeed legitimate on Android (EG: Back button on main screen) you can do it! Re @evenprimes post - Why do it like that? Just use androids native OS multitasking handlers, the OS will appreciate it much more :)
 
E

evenprimes

Guest
Re @evenprimes post - Why do it like that? Just use androids native OS multitasking handlers, the OS will appreciate it much more :)
For the very simple reason that I don't know anything about Android development (or GMS APIs for it). I managed to blunder my way to that option first, and it worked well enough for personal use while developing. (On the other hand, dividing by 0 could satisfy that requirement....) I'll look into these native OS multitasking handlers of which you speak.
 
Last edited by a moderator:
W

Wraithious

Guest
(On the other hand, dividing by 0 could satisfy that requirement....).
Haha thats awesome!
But yea I think all you really need is the onBackPressed method and either just simply call Super.onBackPressed(); in it or if the extension is actually for doing other things call finnish(); or System.exit(0);
 
M

Mann_mit_Hut

Guest
Hey guys,

so do we have a simple solution here? Because usually an android app has an exit button (that simply calls game_end()), wich previously sent the game to the background, wich was absolutely what i expected.
The solution can't be to make an android extension just to simply end (or suspend) the app.

But yea I think all you really need is the onBackPressed method and either just simply call Super.onBackPressed(); in it or if the extension is actually for doing other things call finnish(); or System.exit(0);
FYI, the back button on android triggers the "backspace" key, wich you can simply use in your app ;)
 
W

Wraithious

Guest
Hey guys,

so do we have a simple solution here? Because usually an android app has an exit button (that simply calls game_end()), wich previously sent the game to the background, wich was absolutely what i expected.
The solution can't be to make an android extension just to simply end (or suspend) the app.


FYI, the back button on android triggers the "backspace" key, wich you can simply use in your app ;)
Yep I've been using that way for years, when the player presses the back button I use it to delete any game resources first and then call game_end(); and I've never had any problems with that, but im using early access and haven't (and probably won't) upgraded to to the standard gms, apparently from all these topics in it that version doesn't allow you to call game_end() anymore so, like I and others said, if you have the newest gms stable you'd have to do it in an extension i guess.
 

RangerX

Member
I don't know if you guys realise its only GMS getting "better" as in more compliant to Android programming guidelines?
If they were really severe during game approval, they would refuse your game for being able to stop instead of going in background. Am already surprised how they can let this pass. Afterall its a huge change in behavior between an app that respects this rule and another one that doesn't.

This said, you wanted to say the real solution isn't to find or make an extension. This is not the right information. The right way to do things is to learn how to make a game while respecting the platform's holder programming guidelines and rules regarding their development liscence they gave/sold you.
 

zbox

Member
GMC Elder
I don't know if you guys realise its only GMS getting "better" as in more compliant to Android programming guidelines?
If they were really severe during game approval, they would refuse your game for being able to stop instead of going in background. Am already surprised how they can let this pass. Afterall its a huge change in behavior between an app that respects this rule and another one that doesn't.

This said, you wanted to say the real solution isn't to find or make an extension. This is not the right information. The right way to do things is to learn how to make a game while respecting the platform's holder programming guidelines and rules regarding their development liscence they gave/sold you.
But it is in the guidelines - Perfectly legitimate to have the back button exit the game when you are at a root menu, in fact it is expected.

Open literally any app and press back at the root menu - See what happens :)
 

RangerX

Member
But it is in the guidelines - Perfectly legitimate to have the back button exit the game when you are at a root menu, in fact it is expected.

Open literally any app and press back at the root menu - See what happens :)
What do you mean by "root menu"? I also don't have a "back" labelled button on my Android phone.
 

zbox

Member
GMC Elder
What do you mean by "root menu"? I also don't have a "back" labelled button on my Android phone.
Root menu means the top menu - the menu, usually, that you open the app to before going into other menus. Android users expect that if they press the back button a lot of times, they'll navigate up the menu tree to the root menu and then to the home screen.

I guess that's interesting your phone doesn't have one but that is not a mainstream android feature (the lack thereof). As far as I know, all flagship and most non-flagship androids contain a software or hardware back button (Galaxy s9's, Pixels, etc)
 
W

Wraithious

Guest
I don't know if you guys realise its only GMS getting "better" as in more compliant to Android programming guidelines?
If they were really severe during game approval, they would refuse your game for being able to stop instead of going in background. Am already surprised how they can let this pass. Afterall its a huge change in behavior between an app that respects this rule and another one that doesn't.

This said, you wanted to say the real solution isn't to find or make an extension. This is not the right information. The right way to do things is to learn how to make a game while respecting the platform's holder programming guidelines and rules regarding their development liscence they gave/sold you.
So... how do you exit your apps then? and how do you program your android games to end the game when the player doesn't want to play anymore? as @zbox said that is the expected behavior of an android app, if it's an actual app pressing back goes to previous screens until you 'exit' the app, in a video game you wouldn't want to press the back button to go back to each screen or room in your game until it finally reaches the start room and one more press exits the game, that makes no sense.
 

RangerX

Member
ok, I see what you mean now. I do have a back virtual button. I was looking for real buttons LOL
Now I did a test with Whatsapp. I enter Whatsapp and press back, the phone goes back to its "desktop" yes. But the app doesn't close, it goes in the background. Just like I expected.
Are you guys mistaking going in the background and closing?
 
W

Wraithious

Guest
ok, I see what you mean now. I do have a back virtual button. I was looking for real buttons LOL
Now I did a test with Whatsapp. I enter Whatsapp and press back, the phone goes back to its "desktop" yes. But the app doesn't close, it goes in the background. Just like I expected.
Are you guys mistaking going in the background and closing?
Yep that's what is supposed to happen, to elaborate further, android wants when you press back that your app goes back to the previous 'page' of your app, if you are on the first page of your app it 'closes' and goes to the background, then later if the user presses the menu button on their device (this could be called menu or recently closed apps or something else) then the app is expected to open on the page it left off at. So there's 2 separate issues there, a 'game' and an 'app'.
But what I'm gathering with this whole 'Don't completely kill the game' thing is that android and google play want you to save the state the app is in if the player or app user presses the back button, resulting in if they later press the 'menu' button and click on the game or app it will open where it left off in both 'game' and 'app' conditions?
The problem is, and I have just tested this, when you use game_end(); it does indeed go into the background, BUT when you click it from the recently closed apps menu the game starts from the beginning unless you make your game save it's state in which case it STILL starts from the beginning unless you also save a variable to a file only if the back button was pressed and then on game load check if that variable in the file is true and load the saved game/app.
I would like to know tho, how are we supposed to implement this technique if the game_end(); function has been disabled for android in this new GMS update? Did they make it so the back button will exit the game to the background automatically? because I know if you don't use the back button in code your game will do absolutely nothing when it's pressed. Can you guys that have the updated GMS version that disabled the game_end(); function elaborate on this? what exactly does the back button do now?
 

RangerX

Member
I didn't test it but I was suspecting that save state that lets you take back the game from the "recent app" menu was handled by the OS itself. Also the app closing (kill) would also be done by the OS when you swipe the game out of the "recent apps".

That would make sense since they removed "game_end()".
 

zbox

Member
GMC Elder
Are you guys mistaking going in the background and closing?
The mistake here is believing that the end user would differentiate or that it makes a difference! Why would your end user care if it "closes" or "minimizes" on a phone? I'm operating on the same principle here and that is that those words, in the context of a mobile OS, are synonymous.

The user doesn't care they just want it to go away and fair enough because it practically makes no difference :)
 
E

evenprimes

Guest
I don't know if you guys realise its only GMS getting "better" as in more compliant to Android programming guidelines?
I understand that. And the old game_end() behavior was reportedly corrupting memory, too. In GMS2, they addressed that by making game_end() send the app to the background (good). In GMS1, they addressed it by making game_end() do nothing at all (not so good). This info is from the release notes for 2.1.4.203 and 1.4.1788.

So what is the way to send an app to the background in GMS1 without an extension? The backspace/back button hack lets me find out when someone is trying to go back, but I don't know what to call in place of game_end() when someone presses the back button from the main menu. (I'm pretty new to this stuff, so again I apologize if the answer is obvious to someone else.)
 

zbox

Member
GMC Elder
I understand that. And the old game_end() behavior was reportedly corrupting memory, too. In GMS2, they addressed that by making game_end() send the app to the background (good). In GMS1, they addressed it by making game_end() do nothing at all (not so good). This info is from the release notes for 2.1.4.203 and 1.4.1788.

So what is the way to send an app to the background in GMS1 without an extension? The backspace/back button hack lets me find out when someone is trying to go back, but I don't know what to call in place of game_end() when someone presses the back button from the main menu. (I'm pretty new to this stuff, so again I apologize if the answer is obvious to someone else.)
There's a free marketplace asset that can do it - I forget who it's by
 

RangerX

Member
I understand that. And the old game_end() behavior was reportedly corrupting memory, too. In GMS2, they addressed that by making game_end() send the app to the background (good). In GMS1, they addressed it by making game_end() do nothing at all (not so good). This info is from the release notes for 2.1.4.203 and 1.4.1788.

So what is the way to send an app to the background in GMS1 without an extension? The backspace/back button hack lets me find out when someone is trying to go back, but I don't know what to call in place of game_end() when someone presses the back button from the main menu. (I'm pretty new to this stuff, so again I apologize if the answer is obvious to someone else.)
The way you describe it is pretty clear. Sounds like a bug.
If that's true they really need to fix this before Sunset.
 
L

Lodmot

Guest
Bumping this because I'm pretty annoyed with it.

I was just testing a build of my game tonight and was baffled to find that game_end doesn't do anything on Android anymore. At first I thought it was something wrong with my code, but then I decided to search on Google about it and came across this topic.
I know on iOS it won't work because that's part of Apple's requirements, but on Android it SHOULD do SOMETHING.
In the manual, it explicitly says that game_end() will work on Android:

  • It will report an error on the iOS module as it is against the conditions of their respective Marketplaces.
  • It will silently fail on the HTML5 module.
  • It will work on Windows (including Steam Workshop), Android, Linux and Mac.
Either have it work, or otherwise if it's not supposed to, modify your manual to reflect what the function actually does. Simple as that. Thank you.
 
W

Wraithious

Guest
Bumping this because I'm pretty annoyed with it.

I was just testing a build of my game tonight and was baffled to find that game_end doesn't do anything on Android anymore. At first I thought it was something wrong with my code, but then I decided to search on Google about it and came across this topic.
I know on iOS it won't work because that's part of Apple's requirements, but on Android it SHOULD do SOMETHING.
In the manual, it explicitly says that game_end() will work on Android:



Either have it work, or otherwise if it's not supposed to, modify your manual to reflect what the function actually does. Simple as that. Thank you.
There are a couple things you can do, first is very simple, exit the app by pressing the phone's HOME button, in this way your app can be returned to the state it was in before the home button was pressed. HOWEVER if you have volatile resources (like surfaces for example) you must re create them.
The second thing you can do if you want to kill the app (it still goes into the stack of apps in the phone's menu button, but selecting your app will restart the game) is make a very simple extension that has 1 function, and closes the app in the correct way. The below spoiler shows the 10 steps in illustrated instructions on how to make the extension, to use it just call exitTheApp(); anywhere you want in gamemaker.
 

Joe Ellis

Member
there are too many posts for me to read, but I noticed than game_end() doesn't end a loop if it's in one, so you'd have to put break or exit right after it, just a little tip lol
 
L

Lodmot

Guest
There are a couple things you can do, first is very simple, exit the app by pressing the phone's HOME button, in this way your app can be returned to the state it was in before the home button was pressed. HOWEVER if you have volatile resources (like surfaces for example) you must re create them.
The second thing you can do if you want to kill the app (it still goes into the stack of apps in the phone's menu button, but selecting your app will restart the game) is make a very simple extension that has 1 function, and closes the app in the correct way. The below spoiler shows the 10 steps in illustrated instructions on how to make the extension, to use it just call exitTheApp(); anywhere you want in gamemaker.
Thanks for the tip, I'll definitely try that out. :)
It was just frustrating because I spent like $400+ on this software, I would expect a simple function like ending the game to work normally/as it's described in the manual.
Thank you for sharing that info though!

UPDATE: I just tried the 2nd method, and that's exactly what I was looking for! Thanks man. ;D
 
Last edited by a moderator:
W

Wraithious

Guest
Thanks for the tip, I'll definitely try that out. :)
It was just frustrating because I spent like $400+ on this software, I would expect a simple function like ending the game to work normally/as it's described in the manual.
Thank you for sharing that info though!

UPDATE: I just tried the 2nd method, and that's exactly what I was looking for! Thanks man. ;D
You're welcome I'm glad that fixed it!
 
G

Guest User

Guest
You can't close your game on IOS and Android. Its a requirement from the platforms holders themselves, a programming guideline that is part of their development liscencing.
This is why "game_end()" won't work and its not a bug, its the platforms that are asking for this. On mobile when you game ends it doesn't because it stays available in a "recent app" list. Then there's an OS function that truly closes your game when you swipe it from the "recent app list".
Yes you can, you were able to do it in a earlier version of Gamemaker:Studio. Then after it got updated you were no longer able to do so. The quit event use to work for android at least. I have an app that was made in that version and it works.
 
Top