Detect when an android app goes to the background
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Detect when an android app goes to the background
Hi All,
For the application that I'm working on now, I need somehow to change the app image in background mode when displaying all of the open applications on a mobile device(to hide some sensitive data). I'm looking for a way to detect when an android app goes to the background and come back to foreground.
Before spending time to wrap that functionality with Java FFI capabilities I want to ask if somebody does this or know any way to do this without externals?
Many thanks,
Gurgen
For the application that I'm working on now, I need somehow to change the app image in background mode when displaying all of the open applications on a mobile device(to hide some sensitive data). I'm looking for a way to detect when an android app goes to the background and come back to foreground.
Before spending time to wrap that functionality with Java FFI capabilities I want to ask if somebody does this or know any way to do this without externals?
Many thanks,
Gurgen
Re: Detect when an android app goes to the background
I can't tell you how many times I've needed to know that. No messages are sent when an app goes to the background on Android, there are no suspend messages (and no resume messages either.)
If you get something working I'd be grateful if you could share it.
If you get something working I'd be grateful if you could share it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Detect when an android app goes to the background
Hi Jacque,
I will let you know about progress.
--
Gurgen
I will let you know about progress.
--
Gurgen
Re: Detect when an android app goes to the background
Just curious and thinking out loud as it were, but is this something the focusedObject could be used to test for?
(psuedo code)
In other words, if the object being focused on isn't part of your android program, doesn't that mean your program is in the background by default?
Course, this could be faulty logic, just woke up
(psuedo code)
Code: Select all
on mouseUp // or android equivalent, I don't code mobile...
if the focusedObject is not a card or control of this stack then // probably needs a repeat loop to test with...
objectToReturn = empty
end if
end mouseUp
Course, this could be faulty logic, just woke up
Re: Detect when an android app goes to the background
For iOS we have found the way how to check it.
mergNotify - part of mergExt
Hope this is helpful .
--
Gurgen
mergNotify - part of mergExt
Code: Select all
on openStack
mergNotify "UIApplicationWillResignActiveNotification"
mergNotify "UIApplicationDidBecomeActiveNotification"
end openStack
on UIApplicationWillResignActiveNotification pUserInfo
// Your code before the app goes to background
end UIApplicationWillResignActiveNotification
on UIApplicationDidBecomeActiveNotification pUserInfo
// Your code after the app comes back to foreground
end UIApplicationDidBecomeActiveNotification
--
Gurgen
Re: Detect when an android app goes to the background
Thanks, but for now I'm mostly developing for Android. I'm hoping Monte wraps all his many iOS externals so they are compatible with that OS.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Detect when an android app goes to the background
Unfortunately no. When an Android app goes into the background it is inaccessible. The user doesn't see it and can't interact with it until they re-open the app. However it does stay in RAM for a varying amount of time until the OS needs the memory, when it is summarily deleted. There is no notification when that happens. If the app is still in RAM but "closed" there are no messages sent when the user re-opens it because technically it is still open; that is, it doesn't relaunch, it just re-appears.bogs wrote:Just curious and thinking out loud as it were, but is this something the focusedObject could be used to test for?
(psuedo code)In other words, if the object being focused on isn't part of your android program, doesn't that mean your program is in the background by default?Code: Select all
on mouseUp // or android equivalent, I don't code mobile... if the focusedObject is not a card or control of this stack then // probably needs a repeat loop to test with... objectToReturn = empty end if end mouseUp
Course, this could be faulty logic, just woke up
We could really use "suspend" and "resume" messages so the app knows when to take any necessary actions whenever the app comes to the front. If the OS has deleted the app from RAM then you do get all the usual startup/open-whatever messages. The problem is, when it is idling in the background and the user re-opens it, none of those occur.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Detect when an android app goes to the background
Good to know Jacque, thank you for the explanation.
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
Re: Detect when an android app goes to the background
Hi Jacques,jacque wrote: ↑Wed Jul 12, 2017 7:27 pmWe could really use "suspend" and "resume" messages so the app knows when to take any necessary actions whenever the app comes to the front. If the OS has deleted the app from RAM then you do get all the usual startup/open-whatever messages. The problem is, when it is idling in the background and the user re-opens it, none of those occur.
Do you know if this suspend-resume messages issue was ever resolved for Android (it's a ways off in my plans, but I will be thinking of migrating my Organize app to Android at some point, and a lot of what I do depends on being able to recognize these transitions).
And while I am thinking of it, do you know if there is iOS notification for when the display is turned off? It doesn't appear to me that that in itself triggers a UIApplicationWillResignActiveNotification message, although it might do so after a certain amount of time elapses (not tested).
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
Re: Detect when an android app goes to the background
As far as I know, suspend/resume are still not implemented on mobile. Here's the bug report:
https://quality.livecode.com/show_bug.cgi?id=16829
I don't know much about the iOS notification behavior, sorry.
https://quality.livecode.com/show_bug.cgi?id=16829
I don't know much about the iOS notification behavior, sorry.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
Re: Detect when an android app goes to the background
Ok thanks. Just to add to this discussion, I have been testing more carefully and have discovered that the "suspend" and "resume" messages are being sent when the user turns on/off the iOS display. I'm not sure how I missed observing that, but it works fine. I am seeing no more than a 3-4 second delay between turning off the iPhone display and seeing an update to a dropbox copy of the database. Fast enough for my purposes.jacque wrote: ↑Mon Oct 04, 2021 10:58 pmAs far as I know, suspend/resume are still not implemented on mobile. Here's the bug report:
https://quality.livecode.com/show_bug.cgi?id=16829
I don't know much about the iOS notification behavior, sorry.
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
Re: Detect when an android app goes to the background
Interesting, I'll have to try it on Android when I get a chance. The dictionary still does not list mobile in the supported platforms and the bug report hasn't updated, so I didn't even try.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
Re: Detect when an android app goes to the background
I wonder if Monte would be interested in adding Android to his mergNotify library. I'm using...
Code: Select all
mergNotify "UIApplicationWillResignActiveNotification" -- enables the app to detect when it is moving into the background
mergNotify "UIApplicationDidBecomeActiveNotification" -- and when it is being brought back to the foreground
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
Re: Detect when an android app goes to the background
Hi Jacque, I think your wish has been answered. Check the release notes for LC 10.0.0 dp6...
Mobile suspend and resume messages
The suspend and resume messages are now supported on mobile platforms.
On iOS, suspend and resume messages are now sent to the current card of the default stack when the application becomes active and inactive respectively, corresponding to the lifecycle events applicationWillResignActive and applicationDidBecomeActive.
On Android, suspend and resume messages are now sent to the current card of the default stack when the application is paused and resumed respectively, corresponding to the Activity's onPause and onResume lifecycle events.
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS