Android - quitting application fails

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
semiplay
Posts: 13
Joined: Tue Mar 18, 2008 7:32 pm

Android - quitting application fails

Post by semiplay » Sun May 15, 2011 1:33 pm

I've tried a few ways to close an app on Android - (attaching this code to a button)
close the defaultStack, close this stack, and quit --- all of them cause the app to freeze, and then android allows me to force quit the app after a few seconds.

I've tested this on both the emulator and directly on a phone with the same results.

Anybody seen this, or have suggestions on how to close the app successfully?

Thanks,

Mark

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7238
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Android - quitting application fails

Post by jacque » Sun May 15, 2011 7:54 pm

Well, it shouldn't crash like that, so that's a bug. But Android apps don't really quit, and you shouldn't even try. The Home hardware button will close your app and go back to the launcher screen. Android OS expects to control the app behavior, and manages all memory and the state on its own. It caches the app in RAM so that it can quick-start when the user goes back to it, and pulls it out of memory and shuts it down if it needs RAM or the app hasn't been used for a while. Very few apps try to control their own quitting process. In fact, there are special apps you can get whose only function is to quit any running processes, because apps are expected to stay resident. These utilities are now discouraged in Froyo (Android 2.2) because it interferes with the OS, so their use is now deprecated and unadvised.

The short answer is: let the user press the Home button to leave your app, and don't try to manage the process yourself.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

semiplay
Posts: 13
Joined: Tue Mar 18, 2008 7:32 pm

Re: Android - quitting application fails

Post by semiplay » Tue May 17, 2011 2:35 pm

Ok, thanks for the info, Jacque!

Paul D
Posts: 116
Joined: Mon May 21, 2007 6:58 pm

Re: Android - quitting application fails

Post by Paul D » Tue May 17, 2011 7:06 pm

It does crash. So whether or not closing is supposed to be handled by the app, it is a bug none-the-less.

I have found that the home button will take you to the home screen and leave any data on the app so if you return to it, any data entered in fields will still be there. It will also ignore the opencard/openstack message upon return. But if you hit the back button, it will actually "quit" the app, you will lose any data on the screen and the next time you open the app it will follow opencard/openstack message. This is on a Galaxy 3G with 2.2 FROYO.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7238
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Android - quitting application fails

Post by jacque » Tue May 17, 2011 8:31 pm

That's good to know, I hadn't realized there was a difference in the hardware button behaviors. The latest release of LiveCode sends a "backKey" message when that key is pressed, so you can trap that if you need to. I haven't tested to see if issuing a "quit" command on "backKey" will crash, but since it quits anyway I guess that's moot.

Hopefully soon we'll get a menu button and a Home button. I could use menus.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

sp27
Posts: 135
Joined: Mon May 09, 2011 3:01 pm

Re: Android - quitting application fails

Post by sp27 » Sat Jun 04, 2011 5:41 pm

I use an Android tablet with 2.3.3. Almost all the apps I have display an app-specific menu when I press the system Menu button. Can such a menu be constructed for an LC app?

sp27

Gene
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 75
Joined: Wed Mar 09, 2011 6:48 pm
Location: Northern California

Re: Android - quitting application fails

Post by Gene » Sat Jun 04, 2011 7:11 pm

Paul D wrote:It does crash. So whether or not closing is supposed to be handled by the app, it is a bug none-the-less.

I have found that the home button will take you to the home screen and leave any data on the app so if you return to it, any data entered in fields will still be there. It will also ignore the opencard/openstack message upon return. But if you hit the back button, it will actually "quit" the app, you will lose any data on the screen and the next time you open the app it will follow opencard/openstack message. This is on a Galaxy 3G with 2.2 FROYO.
My experience on my Samsung Captivate running FROYO 2.2.1 is the same as Paul D's, except for the crash. With all the other commercial apps I have run, the "Back Key" will act much like the back button on a browser, retreating to the previous page in the app until it reaches the top level, where the app truly quits, and displays the home screen. As he says, the "Home" button will take you to the home screen, but you can go back to your app without losing your data or place in the app.

I tried the options originally posted by semiplay (close the defaultStack, close this stack, and quit), and they do not crash, or cause a force close on the Samsung. The screen displays the program listing without obviously crashing. HOWEVER, attempting to relaunch the test app again from the program screen consistently produced (for me) a black screen that then freezes. From there, I have been able to get to a program that will "kill" apps. When applied to the test program loaded on the phone, all is well again. I have read the same type of literature that Jacque cited, so apparently, the Android OS sincerely wants to manage the opening and closing of apps (and memory management) on its own, without any interference.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7238
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Android - quitting application fails

Post by jacque » Sat Jun 04, 2011 9:12 pm

The black screen on startup if the app is in RAM is a known bug but it was supposed to be fixed in 4.6.1. But sometimes I still see it. Might be worth a bug report if there isn't one already.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”