Quitting the app in Android freezes it

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Monox18
Posts: 118
Joined: Tue Nov 25, 2014 9:48 pm
Location: Deggendorf, Germany

Quitting the app in Android freezes it

Post by Monox18 » Fri Jan 08, 2021 10:15 pm

Something is making my app freeze when I try to quit it. Either by directly calling the quit command, or by pressing the back key and passing the backKey handler. It just freezes and becomes unrensponsive. I am getting getting very frustated by this. My only option so far is just trapping the backKey message and do nothing. So the user has to quit it from the standard OS functions. Very annoying. Testing on Android arm64 with the minimum version set to 7.0 Nougat.

How could I debug the process of what's causing my app to hang? If I can't quit it, is there any command to hide/minimize/send to background the app?

Also I'm testing a more agressive routine to close Everything: pending messages, open sockests and so on... but still doesn't work. The app still freezes.

command quitMyProject
if the environment is "development" then exit quitMyProject
local tStacksInUse, tOpenStacks, tDontClose, tPendingMessages, tOpenSockets
lock messages
--Sockets
put the openSockets into tOpenSockets
repeat for each line mySocket in tOpenSockets
close socket mySocket
end repeat
--Messages
put the pendingMessages into tPendingMessages
repeat for each line myMsg in tPendingMessages
cancel item 1 of myMsg
end repeat
--Stop using stacks
put the stacksInUse into tStacksInUse
repeat for each line myStack in tStacksInUse
stop using stack myStack
end repeat
--Stacks
put the openStacks into tOpenStacks
put "message box,home,tool,Message Box,revTools,revMenubar" & comma & the short name of me into tDontClose
repeat for each line myStack in tOpenStacks
if myStack is not among the items of tDontClose then close stack myStack
end repeat
close me
quit
end quitMyProject
########END OF CODE generated by this livecode app: http://tinyurl.com/j8xf3xq ########
########Code tested with livecode 9.6.1########
Monox
Developing a Cyber Physical System.
https://www.monoxware.com/

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

Re: Quitting the app in Android freezes it

Post by jacque » Sat Jan 09, 2021 6:32 pm

Try removing all these lines:
put "message box,home,tool,Message Box,revTools,revMenubar" & comma & the short name of me into tDontClose
repeat for each line myStack in tOpenStacks
if myStack is not among the items of tDontClose then close stack myStack
end repeat
Except for the mainstack, none of those stacks are in a standalone, they only exist in the IDE. Actually, you don't need to close any stacks since quitting will do that for you, so you can remove that entire section. (BTW, "close" probably isn't what you want here, you probably want "delete".)

I used to do all the cleanup like you do, but I stopped. Just issuing the quit command seems to take care of things with the possible exception of any open sockets that may be active. Try the quit command all by itself and see if that works. If so, you can selectively add in the other sections if necessary.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Monox18
Posts: 118
Joined: Tue Nov 25, 2014 9:48 pm
Location: Deggendorf, Germany

Re: Quitting the app in Android freezes it

Post by Monox18 » Sat Jan 09, 2021 8:01 pm

This is the simplest form of quitting that I have tried. Putting this code at the mainstack script:

Code: Select all

on backKey
  quit
end backKey
Once I open the app, exiting with the back button works with that code. As I navigate to others screen (e.g. Home) and then press back button to quit, the app freezes and stops responding. Doesn't properly quit. The code I posted was a more aggressive cleanup to try to determine what could be causing my app to hang. Even with canceling pending messages and closing opened Sockets, it still freezes/crashes.

I'm pretty certain that by the time I arrive back to Login Screen, I have already closed everything. Loops, sockets, and so on... I don't know what possibly could make the app fail to quit.

I don't know how to debug this process either.
Monox
Developing a Cyber Physical System.
https://www.monoxware.com/

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

Re: Quitting the app in Android freezes it

Post by jacque » Sat Jan 09, 2021 8:48 pm

You can try getting the result after the quit command:

Code: Select all

quit
answer the result
But I'm not sure the quit command actually gives a result. Another possibility is that stacks can't close if the handler is still running. To get around that:

Code: Select all

on backKey
 send "quit" to me in 1 millisecond
end backKey
But since LC does quit if you don't navigate the stack, I'm not sure that's the problem either. One more thing to try:

Code: Select all

on backKey
 send "quit" to me in 1 millisecond
 exit to top
end backKey
I don't know of any way to specifically put the app in the background, but if you pass the backKey command Android OS should take over and go back to the launcher.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Monox18
Posts: 118
Joined: Tue Nov 25, 2014 9:48 pm
Location: Deggendorf, Germany

Re: Quitting the app in Android freezes it

Post by Monox18 » Sun Jan 10, 2021 4:35 pm

Thank you for all the suggestion but the problem persist. It was worth a try. Even passing the backKey and letting the Android OS handle it still causes it to freeze sometimes. For now I will just trap it and do nothing.

For now I want to finish making my Windows app compatible with Android. This is the last and only bug left. Later on I will start creating new stacks and testing what could be the root of the problem. Maybe it could be a bug. If I were developing and Android app from scratch probably I would have noticed earlier. But given that I have a lot of commands for Windows, it's possible one of those who aren't Android supported could randomly affect this behavior. Will find out later. If you know of some way of debugging this behavior, please let me know.
Monox
Developing a Cyber Physical System.
https://www.monoxware.com/

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

Re: Quitting the app in Android freezes it

Post by jacque » Sun Jan 10, 2021 10:04 pm

Did you ever see any info in the result?

Code: Select all

quit
answer the result -- may be empty
or:

Code: Select all

try
  quit
catch tErr
  answer tErr
end try
You can also try remote debugging which is very useful. Set a breakpoint at the quit command, cable your phone to the computer, and follow these instructions:
https://lessons.livecode.com/m/4071/l/6 ... e-debugger

On Android remote debugging won't work until you turn on USB Debugging in the Developer section of the phone's Android Settings. If you don't see Developer settings, you'll need to do this: https://www.howtogeek.com/129728/how-to ... droid-4.2/
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Monox18
Posts: 118
Joined: Tue Nov 25, 2014 9:48 pm
Location: Deggendorf, Germany

Re: Quitting the app in Android freezes it

Post by Monox18 » Tue Jan 26, 2021 2:32 am

Hi Jacque, Thanks for all suggestions!

I can't use remote debugging because that's only for business license and I have Indy.

The answer the result and try catch were good ideas but the problem is worse than I expected. I think I found the culprit. It is the external tsNet. I tried the same suggestion with the tsNetClose right before quitting the app but instantly crashes even in the IDE. Because it crashes my IDE the same way my Android app dies without response, then I assume that when the app is quitting and LC is closing everything, somewhere when it starts closing tsNet it crashes. It doesn't show any debugging options.

Code: Select all

   try
      tsNetClose -- It makes both IDE and Android crash.
   catch tError
      answer tError
   end try
So I went back and reviewed all my code where I'm calling this external and found out there were a couple handlers where I wasn't closing the connection. I have now ensured that all connections are properly closed with tsNetCloseConn command. This has greatly improved the quit process. Instead of always crashing, now it's 'once in a while'. I guess I still have to continue exploring if somehow connections are remaining open, I must be missing something...Anyway, it is stated in the documentation: tsNetClose - Closes all open connections and disables the tsNet external. Even if I had open connections when quitting, the engine should close them.
Monox
Developing a Cyber Physical System.
https://www.monoxware.com/

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

Re: Quitting the app in Android freezes it

Post by jacque » Tue Jan 26, 2021 7:22 pm

If it's crashing it needs a bug report. LC should never crash. https://quality.livecode.com
You may get a workaround when LC examines the problem. Or at least a fix.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Monox18
Posts: 118
Joined: Tue Nov 25, 2014 9:48 pm
Location: Deggendorf, Germany

Re: Quitting the app in Android freezes it

Post by Monox18 » Tue Jan 26, 2021 8:28 pm

Monox
Developing a Cyber Physical System.
https://www.monoxware.com/

Post Reply

Return to “Android Deployment”