Know if the app in Android has been in the background?

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Know if the app in Android has been in the background?

Post by Mag » Sat Nov 02, 2013 1:25 pm

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?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Know if the app in Android has been in the background?

Post by Mark » Tue Nov 12, 2013 2:19 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Know if the app in Android has been in the background?

Post by Mag » Sun Nov 17, 2013 8:04 pm

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.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Know if the app in Android has been in the background?

Post by Mark » Sun Nov 17, 2013 8:08 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Know if the app in Android has been in the background?

Post by jacque » Mon Nov 18, 2013 8:42 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Know if the app in Android has been in the background?

Post by Mark » Mon Nov 18, 2013 9:17 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Know if the app in Android has been in the background?

Post by Mag » Mon Nov 18, 2013 9:19 pm

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?
Last edited by Mag on Mon Nov 18, 2013 9:26 pm, edited 2 times in total.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Know if the app in Android has been in the background?

Post by Simon » Mon Nov 18, 2013 9:23 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Know if the app in Android has been in the background?

Post by Mag » Mon Nov 18, 2013 9:29 pm

I Simon, surely there is something that changes when the app is in background. We have just to find it.
Last edited by Mag on Tue Nov 19, 2013 10:07 am, edited 2 times in total.

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Know if the app in Android has been in the background?

Post by Mag » Mon Nov 18, 2013 9:33 pm

Jacque, so the app quits when the user presses the Back button? Interesting, I thought the app does not shut even in that case.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Know if the app in Android has been in the background?

Post by jacque » Mon Nov 18, 2013 11:02 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Know if the app in Android has been in the background?

Post by Mark » Mon Nov 18, 2013 11:19 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Know if the app in Android has been in the background?

Post by Simon » Mon Nov 18, 2013 11:24 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply