Android Question Interesting CallSubDelay problem

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I use to have a loop that was something like this
B4X:
For RecordCount = 0 to ShowRecords.Size-1
     '  Display some information on the screen so user knows what record is being processed
     DoEvents

     ' Process the record
next

When DoEvents became Taboo I changed the code to
B4X:
Public Sub ShowRecord
     '  Display some information on the screen so user knows what record is being processed
     '  Process the record
     '  Pseudo code
     If more records then CallSubDelayed(me, "ShowRecord")
end sub

NOW the interesting problem I found is this
While the records are being displayed if the user hits the back key I would leave the Activity and in the Activity_Pause routine if closed by user I would call Activity.Finish

If the user then click to come back into the Activity the CallSubDelayed that was pending would fire off and jump into ShowRecord and the app would crash because not all the things needed were initialized (I am assuming because of the Activity.Finish)

Removing the Activity.Finish has cleaned up the problem but it seems to me that calling Activity.Finish should have cleared any pending CallSubDelayed calls.

The reason I was calling Activity.Finish when the user hit the back key was because I was trying to track down some memory problems and wanted to make sure everything was cleared when leaving.

Just an interesting problem with CallSubDelayed.

AS for my memory problems. I have come to the conclusion that the garbage collector doesn't always free up used memory fast enough and by adding a timely pause Sleep(500) in the modules that were having problems has made all the out of memory problems disappear.
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
What is the question? I do not see any call tp CallSubDelayed. You should upload a project which shows the issue
 
Upvote 0
Top