Page 1 of 1
Know if the app in Android has been in the background?
Posted: Sat Nov 02, 2013 1:25 pm
by Mag
Hi all,
Does anyone know a way to know if an app in Android has been in the background and then came back to the foreground?
Re: Know if the app in Android has been in the background?
Posted: Tue Nov 12, 2013 2:19 pm
by Mark
Hi,
The last time when I made an app for Android, it behaved as if it always restarted when it cam back to front. I just saved the current state of the app in a text file on closeStack or shutdown and rebuilt that state when the stack re-opened.
Kind regards,
Mark
Re: Know if the app in Android has been in the background?
Posted: Sun Nov 17, 2013 8:04 pm
by Mag
Hi Mark, thank you for your replay. In my tests the previous app continue to run after you start using a new app (for example if the app is playing a song, the song continue to play in bg), maybe it's time I do new tests, things could are changed since the new releases of LC.
Re: Know if the app in Android has been in the background?
Posted: Sun Nov 17, 2013 8:08 pm
by Mark
Hi Mag,
Actually, I did a test and it seems that LiveCode apps are now paused instead of aborted, from 6.? onwards.
Kind regards,
Mark
Re: Know if the app in Android has been in the background?
Posted: Mon Nov 18, 2013 8:42 pm
by jacque
Android does not shut down apps unless it need the memory or system resources, or if your app quits when the user presses the Back button to go to the launcher. Usually the app will continue running for at least a little while and it will quit and be erased from RAM at an undetermined time. It depends on what the user does, how many other apps the user opens, and many other factors.
The safest way to deal with the problem is to always save the current state before shutdown, and restore it again when the app restarts.
Re: Know if the app in Android has been in the background?
Posted: Mon Nov 18, 2013 9:17 pm
by Mark
Hi Jaque,
Android doesn't shut down apps, but LiveCode apps used to quit instead of pause when going into background mode. This seems to have been fixed somewhere between 5.5 and 6.1.
Kind regards,
Mark
Re: Know if the app in Android has been in the background?
Posted: Mon Nov 18, 2013 9:19 pm
by Mag
Hi Jacque, thank you for the explanation, it 'something that actually knew which is the reason of this post (reading the other post I tough that something is changed in new versions). So, now I can back to my original question: somebody knows if there is a way to know when the app goes in bg/it's running in bg?
Re: Know if the app in Android has been in the background?
Posted: Mon Nov 18, 2013 9:23 pm
by Simon
Hi Mag,
From my research I found the answer to be No.
I had a game that played music and could not find a way to tell if the game was in focus (or backgrounded) so the music kept playing even when the app was not in focus.
Simon
Re: Know if the app in Android has been in the background?
Posted: Mon Nov 18, 2013 9:29 pm
by Mag
I Simon, surely there is something that changes when the app is in background. We have just to find it.
Re: Know if the app in Android has been in the background?
Posted: Mon Nov 18, 2013 9:33 pm
by Mag
Jacque, so the app quits when the user presses the Back button? Interesting, I thought the app does not shut even in that case.
Re: Know if the app in Android has been in the background?
Posted: Mon Nov 18, 2013 11:02 pm
by jacque
Mag wrote:Jacque, so the app quits when the user presses the Back button? Interesting, I thought the app does not shut even in that case.
It's been a while since I made an Android app so I could be wrong on that. I just tried to test it on my last app but of course I can't tell because I've got it saving the state when the Back button is pressed.
Re: Know if the app in Android has been in the background?
Posted: Mon Nov 18, 2013 11:19 pm
by Mark
Hi,
I just did a quick test on my Android 2.3.3 device. I don't see a way to stop an application other than to force quit it in the application manager. I can press the home and back buttons on the device or the back button on the screen but nothing stops the app.
Kind regards,
Mark
Re: Know if the app in Android has been in the background?
Posted: Mon Nov 18, 2013 11:24 pm
by Simon
The Back, Menu and Search buttons can be trapped and with the Back, on closeStack or any of the others can be acted upon.
But the Home button is the problem.
Simon