Page 1 of 1

Relaunhing app only works every 2nd try

Posted: Wed Sep 03, 2014 7:10 pm
by Ledigimate
Hi

After quitting my app on the device, relaunching it only works on every 2nd try. It otherwise only shows a black screen for a few seconds and then quits. Has anyone else had this problem?

I've noticed that each time I quit the app, the Application Manager would show that the app is still running, giving the option to "Force close" it. How can I get the app to close completely every time I quit it, so it would relaunch properly on every try and not just every 2nd try?

Thanks

Gerrie

Re: Relaunhing app only works every 2nd try

Posted: Wed Sep 03, 2014 7:44 pm
by shawnblc
By no means am I an expert, and I'm sure there's probably a better way, but it seems to work. Perhaps one of the LC gurus will chime in.

In my preOpenStack stack handler

Code: Select all

set the destroyStack of this stack to true
and in my closeStack handler

Code: Select all

quit  //instead of close stack

Re: Relaunhing app only works every 2nd try

Posted: Wed Oct 08, 2014 5:37 pm
by Ledigimate
Sorry about waiting so long before posting this reply.

I did as Shawn suggested, but the problem persists. It seems as though the Android OS suspends the app before it could finish closing, and then when I try to launch the app again, the app is resumed and finishes closing instead of launching. Has anyone else had this happen?

- Gerrie

Re: Relaunhing app only works every 2nd try

Posted: Wed Oct 08, 2014 6:10 pm
by Traxgeek
Hi,

A while ago, I encountered a similar issue, BUT, like shawnbic says, using
[1] the 'set the destroyStack of stack "MyStackName" to true' (for the main stack AND each sub-stack) and
[2] 'quit' seems to have remedied the issue...

Just my penny's worth...
(I was using LC commercial 6.6.2 on an ASUS 701 Infinity Transformer using ICS)

Let us know if this remedies your issue OR if you find a different 'work around' please.
HTH.

Trax.

Re: Relaunhing app only works every 2nd try

Posted: Wed Oct 08, 2014 6:46 pm
by Ledigimate
Trax, I tried your suggestion, but still no joy.

In my card script I have:

Code: Select all

on backKey
   exitTheApp
end backKey
and in my stack script I have:

Code: Select all

on exitTheApp
   put the stacksinuse into tStacksInUse
   repeat with i = 1 to the number of lines of tStacksInUse
      stop using stack line i of tStacksInUse
   end repeat
   
   put the openStacks into tOpenStacks
   repeat with i = 1 to the number of lines of tOpenStacks
      set the destroyStack of stack line i of tOpenStacks to true
   end repeat
   quit
end exitTheApp
The above should work, right?
But in this particular app I'm working on, it doesn't work and I just can't figure out why.

Re: Relaunhing app only works every 2nd try

Posted: Thu Oct 09, 2014 10:45 am
by Traxgeek
Hi Ledigimate,

I've not tried it your way specifically...

The major difference for me is that I script the
'set the destroyStack of stack "MyStackName" to true' in the 'preopenstack' handler

The only thing I can't prove here (without trying it) is whether you actually need to do half of what you're doing and whether after 'stop using stack...' the 'set destroystack...' command has any effect...

Three ideas :
[1] just an idea : place a 'wait for 1 second' just before the 'quit' - I doubt this will have any effect though - but possibly worth a try...
[2] relocate your 'destroystack...' repeat block BEFORE the 'stop using...' repeat block
[3] relocate the 'destroystack'...' repeat block to a preopenstack (main stack) handler and temporarily rem out all other lines except the 'quit' in the 'exitTheApp' handler.

Won't take more than 10 mins to do all three... let us know how you get on (my money's on [3] - for what it's worth !)

HTH.

Trax

Re: Relaunhing app only works every 2nd try

Posted: Thu Oct 09, 2014 3:13 pm
by Ledigimate
Hello Trax,

I tried all three suggestions, but none of that helped. I also replaced the repeat block with explicit "set the destroystack of stack xyzStack to true" statements in case "the openStacks" returned empty.

I've made a backup of my stacks and now I'm deleting and commenting out piece by piece to try and narrow it down. So far I've removed 80% of the cards and code, and I removed all externals, but still no luck. I'll keep chopping off more of the app until I find what's causing it. If I end up with a single stack and a single card with nothing on it, and only three handlers - preOpenStack, backKey, and exitTheApp - and it still doesn't work, then I'll post what's left of my stack here for someone else to have a crack at it.

Re: Relaunhing app only works every 2nd try

Posted: Thu Oct 09, 2014 5:13 pm
by jacque
Remove the "quit" command. Android keeps the app in RAM until it needs to use the memory, so when you restart it immediately the script picks up where it left off (at least that's my theory.) At any rate, a specific quit instruction isn't needed, the OS manages that and LiveCode's default is to quit when the app is closed anyway.

For destroystack, I have my preferences set to create all new stacks with it set to true. Originally it was useful for faster reloading of stacks on slower machines but with today's processors it's unnecessary. For your existing stacks just set it to true in the property inspector, save the stack, and forget about it. There's no need to script it.

The destroystack setting on substacks is immaterial, they are never completely removed as long as the mainstack is open. They are part of the same file so they can't be completely removed.

Re: Relaunhing app only works every 2nd try

Posted: Thu Oct 09, 2014 8:20 pm
by SparkOut
Also there is a setting for stacks in the standalone creator options to set the destroyStack property. Is there a difference here in relation to the destroyStack property of a stack (as opposed to a standalone)?

Re: Relaunhing app only works every 2nd try

Posted: Thu Oct 09, 2014 8:49 pm
by jacque
SparkOut wrote:Also there is a setting for stacks in the standalone creator options to set the destroyStack property. Is there a difference here in relation to the destroyStack property of a stack (as opposed to a standalone)?
Good point. There isn't really a difference in the case of the mainstack. Destroystack would matter if the mainstack opened other document stacks that weren't part of the standalone file.

I wasn't thinking straight.

Re: Relaunhing app only works every 2nd try

Posted: Fri Oct 10, 2014 8:09 am
by Ledigimate
Thanks for all the suggestions.

So if I understand you correctly, there's no need for me to close the app in a script because Android decides when to close the app, right?
But then, if the app picks up where it left off, that would create a problem. I need my app to start over every time it's launched, because the device it runs on is shared among users and the next user shouldn't pick up where the previous user left off. Otherwise I must find a way to make my app detect when it is being relaunched so it can start a new session. I've seen a "relaunch" message in the dictionary, but unfortunately it's not available on Android.

Re: Relaunhing app only works every 2nd try

Posted: Fri Oct 10, 2014 10:54 am
by ChrisMukrow
Can't you use openStack command instead of the relaunch message?

Re: Relaunhing app only works every 2nd try

Posted: Fri Oct 10, 2014 11:38 am
by Ledigimate
@ChrisMikrow, I have an openStack handler in which a new session is started. The problem I'm having is that it only works every 2nd time the app is relaunched. On every odd relaunch the openStack handler is never called, but instead it only shows a black screen and quits after a few seconds.

Re: Relaunhing app only works every 2nd try

Posted: Fri Oct 10, 2014 11:10 pm
by jacque
If the app is still resident in memory, you won't get an openStack message or a shutdown message, so it's hard to know when the app comes to the front again. If Android OS has shut down the app then those messages do occur. I haven't tried it, but you could see if you get a resumeStack message and if so, do your setup in that handler.

If that doesn't work you could try this:

Code: Select all

quit
exit to top
but given the symptoms you describe, I'm not sure it will work.

Another thing to try is to trap the backKey message and do your cleanup there.