Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / If user stops app via phone button, is there a moment to save state of app?

Author
Message
T4r4ntul4
14
Years of Service
User Offline
Joined: 1st Jan 2010
Location: close to my pc
Posted: 8th Jan 2020 17:28
Hi all,

If the user stops the app through pressing the 'stop icon' on their phone or via a button on their phone, is there a possibility to, for example, save the state of the game to a file? or do some other things before really quitting the app?
If yes, where in the code should it be and what functions are there to accomplish this?

Any help is appreciated.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 8th Jan 2020 19:16
The home button is mapped to the escape key. So save when you see the escape key save the state
Qugurun
Valued Member
9
Years of Service
User Offline
Joined: 8th Dec 2014
Playing: AppGameKit
Posted: 8th Jan 2020 19:38
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 8th Jan 2020 20:45 Edited at: 8th Jan 2020 20:46
T4r4ntul4
14
Years of Service
User Offline
Joined: 1st Jan 2010
Location: close to my pc
Posted: 8th Jan 2020 22:47
Hi,

Quote: "The home button is mapped to the escape key. So save when you see the escape key save the state"




It doesnt seem reliable to use above code to catch if a home button is pressed. in my tests with my phone, i only get it to work once out of the minimum of 20 tries.

Do i miss something here?
Or is pressing the button and closing the app too fast to do something in between?
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 8th Jan 2020 23:07
I would implement ALL of the checks
1. Escape key (My apologies. The Escaoe key is mapped to the back key)
2. GetResumed()
3. GetPaused()
T4r4ntul4
14
Years of Service
User Offline
Joined: 1st Jan 2010
Location: close to my pc
Posted: 9th Jan 2020 00:45
GetResumed() doesnt really solve my problem, it only executes if the app comes from the background back to front.

Iam still searching for a solution when the user stops the app unexpected (without the exit button from the app itself) to exit the app. Those 3 things you mentioned dont do this. Are there other solutions to this problem?
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 9th Jan 2020 00:46 Edited at: 9th Jan 2020 02:03
So GetPaused() doesn't do this? In order to get to the Cancel screen you have to pause the app right?
Sorry. My bad. Only applies to Desktop. I'll do some research

*EDIT*

There is a perceptible drop in frame rate just prior to the app going into sleep mode.
In order to make it work i think you would need to average the frame rate and if it strayed a certain amount then save your data.
I would also make sure that after writing out your data you pause for some amount of time before checking again, In case of an unforeseen slowdown that would cause it to constantly write out the file.

Here is a very simple example that will write out a line to a file when the home button is press (or some unforeseen event causes a slowdown)



Hope this helps
Qugurun
Valued Member
9
Years of Service
User Offline
Joined: 8th Dec 2014
Playing: AppGameKit
Posted: 9th Jan 2020 04:12 Edited at: 9th Jan 2020 04:28
T4r4ntul4, Track keystroke.

T4r4ntul4
14
Years of Service
User Offline
Joined: 1st Jan 2010
Location: close to my pc
Posted: 9th Jan 2020 10:19
@blink0k

I was too quick to mark your post as answer. I tested it now a bit longer, and this is whats happening on the (android) phone:

If i have the app open and i press phone button: pause or quit, the app goes to the background, it doesnt execute your code at that moment, only if it goes back to front.
But that wasn't what i tried to do.

What i want is: If the user presses the android button on their phone to pause or quit the app, the code should be executed immediately, not if the app comes to front again. Thats already too late, if the app is on the background they can still close the app while its not running.

Am i trying here to do the impossible?

Qugurun
Valued Member
9
Years of Service
User Offline
Joined: 8th Dec 2014
Playing: AppGameKit
Posted: 9th Jan 2020 10:45
Track the pressing of the Home button through the onUserLeaveHint () "Android - Java" activity method, but as far as I understand it is not implemented in the AppGameKit API .
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 9th Jan 2020 22:52
Quote: "Am i trying here to do the impossible? "

Unfortunately that might be true for Tier1.

Maybe there might be another approach. Are there any other points where you could save the data. Touch event maybe. When does the data change?
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 10th Jan 2020 15:18
I'm somewhat surprised there's a GetPaused() command, yet it doesn't work for mobile. I mean, not to complain too much, but I think apps on mobile tend to lose focus way more often. As for saving progress though, I am pretty sure pressing the Home button doesn't close any apps, nor does the Menu button or Back button. So, unless pressing the Back button instantly activates an End command because you've written that in your code, you should be able to save progress periodically or at important moments. If a user forces an app to end in unintended ways, the blame is on them anyway.

I also think just reading out the Home button input would make any app potentially capable of 'taking a phone hostage' to put it bluntly, so that's probably not ever intended or allowed by Apple nor Google? In fact, I know the Home key on Android is handled by the framework and never passed on to applications (since the API level 1 or basically the first Android version 1.0). I believe the same applies to the Menu button, although no such thing is mentioned on developer.android.com . Maybe we should still have access to the Menu button on Android, but it seems not supported in Tier 1.

The only 'key' on smartphones that responds within Tier 1 is the Back key, which is scancode 27, like Escape on PC. I'd add a Pause screen to that, maybe a save function that kicks in. But I would use an auto-save of sorts when you know your game is being played.

Login to post a reply

Server time is: 2024-05-08 02:47:40
Your offset time is: 2024-05-08 02:47:40