[Android] 'Home' button causes LOVE to cry

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
rhughes
Prole
Posts: 7
Joined: Thu Apr 28, 2016 3:12 am

[Android] 'Home' button causes LOVE to cry

Post by rhughes »

I have a game running on Android. I'm using Love 10.1.

Running the game the first time works fine. If I hit the 'home' button... the big, physical button in the center of my phone... it brings me back to the main screen for my phone. If I then try to run my game again, I will get a black, unresponsive screen, but the music will still play. The music continues playing even if I minimize the game! The only way to stop this is to get into the settings for my phone and force the game to quit.

How can I stop this?

I've currently tried:

1) catching all keypresses that aren't being used and calling love.event.quit().
2) catching loss of focus and calling love.event.quit().

Neither have resolved the issue. :x
xypotion
Prole
Posts: 5
Joined: Fri Sep 09, 2016 1:47 am
Contact:

Re: [Android] 'Home' button causes LOVE to cry

Post by xypotion »

I'm pretty new to Android+Love, but I'm having a problem that might be related to yours. When I launch my game and do some stuff, then press the home button, then tap the game's icon from my home screen, the game reloads from scratch and I lose whatever unsaved progress I made in the game. I.e. love.load() is called again, even though the app is still running in the background. Conversely, when I press the home button, then the Overview/Recents button (where currently open apps are shown), then select my game, love.load() IS NOT called again, and the game picks up right where it was when I pressed Home.

I really want to know how to get the first case to behave like the second case, so love.load() is only called when the app is opened after being explicitly closed. Otherwise, I'll have to implement a "resume game?" feature by constantly saving the game's state to the hard drive and checking for data first-thing in love.load(), in case the player decides to resume by tapping the home-screen icon instead of the Recent Apps list. That seems like a really inelegant solution, plus I know Android can do this because there are apps that DON'T start from scratch when you hide them and then relaunch them from the home screen. Playing with various attributes in AndroidManifests.xml (like android:launchMode="singleInstance" and android:alwaysRetainTaskState="true") has gotten me nowhere, for what it's worth.

rhughes:
1. In your case described above, at "If I then try to run my game again", how were you running the app? Tapping from the home screen, or "resuming" from the Recents? Could it be that you were experiencing the same thing I am, despite hearing your music playing?
2. Did you ever resolve the problem? I would love to know your solution if so.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: [Android] 'Home' button causes LOVE to cry

Post by raidho36 »

I've heard of this problem multiple times but haven't been able to reproduce. Having that said, my phone runs Android 7 and latest LOVE app, and it works flawlessly - in that regard anyway. So it could be that specific version of Android needs app to do very specific things and specific version of LOVE doesn't do them. What versions are you using?
xypotion
Prole
Posts: 5
Joined: Fri Sep 09, 2016 1:47 am
Contact:

Re: [Android] 'Home' button causes LOVE to cry

Post by xypotion »

Hi, raidho36! My device is on Android 6.0.1, and I'm using Love 10.0.0. I just set up the Android+Love stuff this week, so my SDL/NDL/ADK/JDK/whatever all have the most recent versions. Not sure if it's important, but my default.properties file has target=android-19.

Maybe you're right about version capabilities, because I am kind of stumped. You're saying that tapping your game's icon from the home screen does NOT call love.load() if the game is already running in the background?
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: [Android] 'Home' button causes LOVE to cry

Post by Positive07 »

xypotion wrote: Fri Feb 24, 2017 8:26 am I'm pretty new to Android+Love, but I'm having a problem that might be related to yours. When I launch my game and do some stuff, then press the home button, then tap the game's icon from my home screen, the game reloads from scratch and I lose whatever unsaved progress I made in the game. I.e. love.load() is called again, even though the app is still running in the background. Conversely, when I press the home button, then the Overview/Recents button (where currently open apps are shown), then select my game, love.load() IS NOT called again, and the game picks up right where it was when I pressed Home.

I really want to know how to get the first case to behave like the second case, so love.load() is only called when the app is opened after being explicitly closed. Otherwise, I'll have to implement a "resume game?" feature by constantly saving the game's state to the hard drive and checking for data first-thing in love.load(), in case the player decides to resume by tapping the home-screen icon instead of the Recent Apps list. That seems like a really inelegant solution, plus I know Android can do this because there are apps that DON'T start from scratch when you hide them and then relaunch them from the home screen. Playing with various attributes in AndroidManifests.xml (like android:launchMode="singleInstance" and android:alwaysRetainTaskState="true") has gotten me nowhere, for what it's worth.
Most apps you are saying do, save every time, and reload from a state cache. Android always restarts the app when launching from the icon.

LÖVE should fire love.quit, love.visible and/or love.focus, you can save the game and states in one of those callbacks then reload from a file. If LÖVE doesn't fire any of those events when switching to the background and/or restarting the app from the app icon then that's a bug and should be reported to love-android-sdl2 issue tracker. Related issue may be this proposal
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 152 guests