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 / Reopening App

Author
Message
lynnon
3
Years of Service
User Offline
Joined: 9th Nov 2020
Location:
Posted: 30th Mar 2023 20:12
My sister is testing my game on her android phone. When she closes the game and reopens it later it takes her back to the beginning and she has to start over. Can someone please let me know what I am missing so that when she reopens the game she can pick up where she left off? I thought that was automatic. Do I need to add an exit or save button in order to save the progress? I am using tier 1 to develop the game. Thank you.
lynnon
3
Years of Service
User Offline
Joined: 9th Nov 2020
Location:
Posted: 3rd Apr 2023 15:42
My question may not have been clear so hopefully this will help get my question answered or at least get pointed in the right direction. When I play and test my app on my Kindle and hit the home screen to back out of it, when I go back in the game picks up where I left off. When my sister plays my game that she downloaded to her Android and hits the home button, when she goes back in it starts over from the beginning. Can someone help me understand why and what I need to do or include to prevent that? Thank you.

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 3rd Apr 2023 21:27 Edited at: 3rd Apr 2023 21:31
i tested my Ranch Rush APK and it keeps running when minimized. my game allows 20 seconds of play at a time and when i leave & return to it the timer has dropped/has run down completely = end of game, which is what i think is happening with yours.

i inquired on Discord and received the following:
KevinCross wrote: "...You basically need to store the time every frame into a variable and then with GetResumed() calculate the difference between Timer() or GetMillisecond() and the variable that stored the same timer command the last frame.
With this you can calculate how long the game was minimised..."

So, Timer()/GetMilliseconds() keeps ticking and you can use the time difference to detect when the App has lost focus.

kevin provided some code which i took a little further:

somewhere along these lines is the key to what i think we both are experiencing. perhaps a running Duration# that could also tell us that the app has lost focus (regardless of GetResumed()) and be sent to pause() is ideal.

otherwise, if this is what your sister is experiencing, it's odd that your kindle doesn't do the same. it seems it's stopping Timer()?

hope this helps. do post if you further the notion as we would all be interested.

finally, if this IS what you're experiencing, it would apply beyond android so perhaps this thread should be moved to AppGameKit Classic (where more eyes tend to be)? if you somehow determine that YOUR issue is android-specific (since i have no idea what your app is doing), then we'll leave the thread here. let me know.
lynnon
3
Years of Service
User Offline
Joined: 9th Nov 2020
Location:
Posted: 4th Apr 2023 02:24
Thank you for your response. I’ll play around with it and see if your suggestions helped. Makes sense too that it might not be an Android issue. I’ll update once I understand better so this thread can go in its proper place. Thank you so much.
lynnon
3
Years of Service
User Offline
Joined: 9th Nov 2020
Location:
Posted: 8th Apr 2023 16:40
So my issue doesn't seem to be an Android issue so if this can be moved to the proper forum please do so or let me know if I need to repost my question there.

I played around with the code you provided but I still can't seem to get it to work. My game is made up of scenes and after closing and reopening the app it starts over from scene 1. If anyone can help me figure this out or point me in the right direction I would be so grateful. I think if I can get past this one last hurdle I am set. Thank you for your help.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 8th Apr 2023 18:51 Edited at: 8th Apr 2023 18:52
Quote: "My game is made up of scenes"

moved from Android to Studio chat where hopefully someone can help.
Zappo
Valued Member
19
Years of Service
User Offline
Joined: 27th Oct 2004
Location: In the post
Posted: 8th Apr 2023 19:54
This may be way off, but Android has quite a clever memory management system from what I understand. Here are my thoughts on it:

When you leave an app by pressing the "home" button, "back" button or switch to another app, it will try and leave it running in the background. If it decides that a background app hasn't been used in a while or it needs the resources for something else, then it will close it down to free up those resources. Then if you switch back to the app or run it again, it has to basically start from scratch and load everything fresh.

I could be wrong about this as I haven't looked into Android memory management for many years. Basically, if this is correct, if your Android device has very limited resources or has other background apps/tasks that are eating resources then there is a much bigger chance that your app will be shutdown completely to free up it's resources (e.g. memory, CPU) when it gets moved to the background. If you have bucket loads of resources available and very little else running, then there is a better chance it will keep your app running and it's resources assigned while it is in the background.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 8th Apr 2023 20:17 Edited at: 8th Apr 2023 20:19
@lynnon,

Zappo offered some insight on a potential issue but if you provided more details re: your game and experiences, help could be more focused.

example, you offer "When I play and test my app on my Kindle" and go on to advise that your sister "downloaded" the game. does that mean that your Kindle test was a Broadcast? or, did you also download?

with Zappo's idea, is there a chance that her system could be recovering resources while yours is not? ie, specs on the devices but, also, does the game have minimal media or "lots". have you compared a small test app for your sister to see if the issue persists? you advise that it may be multiple scene-related so a small test app that includes this might prove insightful (as would providing a small example of your scene handling for others to scrutinize)?

then, Export options. one is "Wake lock" that "prevents the device from sleeping". is this ticked on both versions? is there a chance that the game went to sleep, was awoken and needed to Restart?

so, lots of questions and "could be"s that you can help dial in for those that might be able to help
Zappo
Valued Member
19
Years of Service
User Offline
Joined: 27th Oct 2004
Location: In the post
Posted: 9th Apr 2023 01:39
I've just double checked my theory on Android memory management and it is correct. When you switch away from an app it goes into a cache. The cache keeps the resources the app uses for as long as possible but it can start to affect overall system performance. For this reason, as the system runs low on resources like memory, it kills processes in the background cache and frees up the memory they use. The following paragraph from Android contains an important piece of guidance when writing apps:

Quote: "The less memory your app consumes while in the cache, the better its chances are not to be killed and to be able to quickly resume. However, depending on instantaneous system requirements, it's possible for cached processes to be terminated at any time no matter their resource utilization."


I hope that helps.
lynnon
3
Years of Service
User Offline
Joined: 9th Nov 2020
Location:
Posted: 10th Apr 2023 14:31
All of you have been very helpful. I emailed and installed the apk to my Kindle to test it. I also use BlueStacks to test my games but I don't know how well I could test this issue using that. Would I possibly be able to use GetResume() in my code somewhere so it maybe picks up where it left off? I don't know; I feel like I should be posting in the beginner forum sometimes. Also, I do have Wake Lock checked. Thanks again.

Login to post a reply

Server time is: 2024-05-02 00:04:46
Your offset time is: 2024-05-02 00:04:46