Detect when an android app goes to the background

Are you developing an External using the LiveCode Externals SDK?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Detect when an android app goes to the background

Postby Gurgen » Mon Jul 10, 2017 12:16 pm

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
Gurgen
 
Posts: 29
Joined: Thu Dec 10, 2015 2:09 pm

Re: Detect when an android app goes to the background

Postby jacque » Mon Jul 10, 2017 4:51 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 3798
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN

Re: Detect when an android app goes to the background

Postby Gurgen » Tue Jul 11, 2017 11:12 am

Hi Jacque,

I will let you know about progress.

--
Gurgen
Gurgen
 
Posts: 29
Joined: Thu Dec 10, 2015 2:09 pm

Re: Detect when an android app goes to the background

Postby bogs » Tue Jul 11, 2017 3:02 pm

Just curious and thinking out loud as it were, but is this something the focusedObject could be used to test for?

(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

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 :)
Image
bogs
 
Posts: 384
Joined: Sat Feb 25, 2017 10:45 pm

Re: Detect when an android app goes to the background

Postby Gurgen » Wed Jul 12, 2017 3:08 pm

For iOS we have found the way how to check it.

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


Hope this is helpful .

--
Gurgen
Gurgen
 
Posts: 29
Joined: Thu Dec 10, 2015 2:09 pm

Re: Detect when an android app goes to the background

Postby jacque » Wed Jul 12, 2017 7:20 pm

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
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 3798
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN

Re: Detect when an android app goes to the background

Postby jacque » Wed Jul 12, 2017 7:27 pm

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)
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

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 :)


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.

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
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 3798
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN

Re: Detect when an android app goes to the background

Postby bogs » Wed Jul 12, 2017 8:04 pm

Good to know Jacque, thank you for the explanation.
Image
bogs
 
Posts: 384
Joined: Sat Feb 25, 2017 10:45 pm


Return to Building Externals/Plugins

Who is online

Users browsing this forum: No registered users and 0 guests