-
Notifications
You must be signed in to change notification settings - Fork 471
love.quit, love.focus and love.visible callbacks not being triggered on Android #2171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Small update on what I've triedIn order to try to have a reliable event on android app pause, I added two lines to // Event.cpp line 496
case SDL_EVENT_QUIT:
case SDL_EVENT_TERMINATING:
case SDL_EVENT_WILL_ENTER_BACKGROUND:
case SDL_EVENT_DID_ENTER_BACKGROUND:
msg = new Message("quit");
break;
// ... This is because they mention in the docs that these events are for when "The application is about to enter the background and may not get CPU for some time. Called on Android in onPause()." However, this doesn't seem to solve the problem or be any better (in fact, quit never gets called when the app enters background). Edit: Fixed a typo in the snippet. |
Can you try to add this code in local ffi = require("ffi")
ffi.cdef("int SDL_SetHint(const char* name, const char* value);")
ffi.C.SDL_SetHint("SDL_ANDROID_BLOCK_ON_PAUSE", "0") I need to rule out something before invstigating further. |
Hello @MikuAuahDark, thank you for your response. I tested your changes with the official binary and now However, Do we need any additional changes besides setting the hint
Also, what are the next steps we should take to find the cause of |
Ok so it looks like SDL blocks the event poll before LOVE have a chance to poll or process for the "focus" event. Thanks for testing. As for the Note Do not count on this method being called as a place for saving data! For example, if an activity is editing data in a content provider, those edits should be committed in either So yeah, for now the best workaround is to save on I'll need to think on how to proceed, if it's something workable in LOVE or SDL upstream. |
Fair enough,
Thanks for the tip!
Okay, if you think of something or would like help with more testing just ping me. Have a great day. |
Consider the following code which tracks the number of times the callbacks
quit
,focus
, andvisible
gets called (using a file for persistence):Now if you generate an embedded APK with this and experiment with it a little, you will see that the callbacks almost never get called (but some of them do get called a few times, like 10% of the time). I am not sure why this inconsistent behavior happens and it doesn't work 90% of the time.
I am trying to save a little bit of game state when the user closes the app, and while I have implemented some sort of auto-save feature every minute or so, I would like to reliably (most of the time) be able to execute a little bit of code to save the state when the user quits the app. Initially I tried with quit, but after seeing it didn't work, I tried with focus and visible too, to find a workaround.
I don't know if there is currently a way to get callbacks for important activity lifecycle events, or at least the most important/useful one... an event when the user exits the app!. It seems to me that SDL for android does support this.
Are there currently any workarounds?
Software version
Desktop:
Mobile:
The text was updated successfully, but these errors were encountered: