Trapping Home Button on Android

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
joel.epsteinBUS31vi
Posts: 135
Joined: Thu Sep 13, 2012 10:25 pm

Trapping Home Button on Android

Post by joel.epsteinBUS31vi » Tue Nov 04, 2014 1:41 am

Hi all -

I'm fairly new to Android development and could use a quick pointer.

Is there a way I can detect if the user has tapped the device's home button?

If not, is there a way to detect if the app has been pushed to the background?

I want to be able to detect separate "sessions" of use. For iOS, I'm using "on ShutDown" and that seems to work, but not for Android.

I'd appreciate any advice you might be able to provide.

Thanks so much.

Joel

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

Re: Trapping Home Button on Android

Post by Simon » Tue Nov 04, 2014 3:33 am

Hi Joel,
Sorry no, really wish there was a way.
You have to build your app as if it could shutdown at any moment.
Pressing the "Home" button only moves your app out of focus, it is still running but could be booted out at anytime the device needed the memory.
iOS does the same thing, so I am surprised if on shutDown code you have will work consistently. You know double tapping the home button shows background apps, yours should be there unless it's a huge memory hog. (Oh.. prior to iOS 8 maybe things have changed).

Come on Widgets!!!

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

joel.epsteinBUS31vi
Posts: 135
Joined: Thu Sep 13, 2012 10:25 pm

Re: Trapping Home Button on Android

Post by joel.epsteinBUS31vi » Tue Nov 04, 2014 3:56 am

Hi Simon -

Thanks for the speedy reply.

I understand the idea of having to build the app so that it might shut down at any moment. That makes sense.

But I am still confused about how to know if the app is out of focus (i.e. in the background).

What if I have sounds or movies playing in my app and the user presses the home key? Do they continue to play? Isn't there a way to know when the app is in the background?

Sorry for being slow on this, I'm just a bit confused.

I appreciate your help.

Joel

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

Re: Trapping Home Button on Android

Post by Simon » Tue Nov 04, 2014 4:09 am

What if I have sounds or movies playing in my app and the user presses the home key? Do they continue to play?
Yes!
That is how I found out about this. Made a game with sound FX and even though it was backgrounded the sounds came through. :roll:
My workaround for that was if there wasn't a touch then it should be silent.
Isn't there a way to know when the app is in the background?
Nope!
Bummer huh?
Here you can help
http://quality.runrev.com/show_bug.cgi?id=11965
Post how urgently you need this... that it will save lives...bring about world peace...feed the hungry. :D

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

joel.epsteinBUS31vi
Posts: 135
Joined: Thu Sep 13, 2012 10:25 pm

Re: Trapping Home Button on Android

Post by joel.epsteinBUS31vi » Tue Nov 04, 2014 4:25 am

Hey Simon -

World peace and feeding the hungry sound great to me.

In the meantime, I'm struggling to figure out how to handle this on my app - if I'm playing an instructional video, I wouldn't expect the user to be touching the screen. So your approach of testing for a touch won't work.

Any ideas?

I appreciate your help.

Joel

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

Re: Trapping Home Button on Android

Post by Simon » Tue Nov 04, 2014 4:50 am

if I'm playing an instructional video
Ahh that may explain why it works on iOS, that takes lots of memory. Or iOS maybe smart enough to know that a video is playing and when the Home button is pressed it shuts down the app.

Sorry, I can't think of a workaround for Android at the moment.

We really really need the promised widgets.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

frankyfratelli
Posts: 1
Joined: Thu Feb 26, 2015 6:00 pm

Re: Trapping Home Button on Android

Post by frankyfratelli » Mon Mar 02, 2015 5:14 pm

was there ever any update to this? stumbled on to this thread seeking the same solution... when my android app goes out of focus, I want to detect so I can pause gameplay or exit altogether (will decide what to do later, after i find out if it's even possible to detect).

I was expecting a way to detect if my current stack goes out of focus and into the background.

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

Re: Trapping Home Button on Android

Post by Simon » Mon Mar 02, 2015 11:28 pm

Hi frankyfratelli,
Welcome to the forum!

Sorry the answer is still no.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply