Labels not updating

35 views
Skip to first unread message

sghughes

unread,
Jul 24, 2015, 10:47:23 AM7/24/15
to MIT App Inventor Forum
I'm trying to code a function which attempts to connect to a Bluetooth device 4 times then fails if a connection can't be made.

The code itself seems to be working, however I'm using the When Screen1.ErrorOccurred function to catch connection failures.

In this code I'm updating a label to show the attempt number and also (for diagnostics) printing the full error message to another label.

The problem I'm finding is that the labels aren't updating until the connect operation has completed.

I've found a few references to this in the forum but I can't find a specific answer as to why and what I can do about it - if anything.

I've tried to attach the blocks in question but due to their size I can't fit them all on the same screen in full. Hopefully this will be enough to explain what I'm doing.

Any ideas how to fix this?

Ai Text Update Error.jpg

Abraham Getzler

unread,
Jul 24, 2015, 11:22:32 AM7/24/15
to MIT App Inventor Forum, sghug...@gmail.com
I blame the while loop in the connect button click routine.
To update the screen, you need to release control until the next event occurs.

Consider either adding a second clock to manage the connection process,
or adding a variable to identify the state (connecting/reading) in your clock.

You an post extra attachments, including that clock routine.

ABG


sghughes

unread,
Jul 24, 2015, 11:35:59 AM7/24/15
to MIT App Inventor Forum, aget...@gmail.com
Ah, I think I understand. It sounds like App Inventor doesn't have any sort of 'automatic house keeping' (for want of a better term) and waits for control to drop back in to the main loop before anything actually happens.

I understand what you are saying about using the clock but I'd have to change so much and make things so complicated I don't think it is worth it just to give the user a retry count-down.

Maybe that is a suggestion for an AI improvement - add a function which allows any background processing to happen at a particular time - sort of a temporary release of control at a point where the app doesn't need to keep hold of the thread. That would make things like this so much easier to achieve!

Taifun

unread,
Jul 24, 2015, 12:11:26 PM7/24/15
to MIT App Inventor Forum, sghug...@gmail.com

I understand what you are saying about using the clock but I'd have to change so much and make things so complicated I don't think it is worth it just to give the user a retry count-down. 
to work with the clock is not complicated, see my doSomething example here https://groups.google.com/forum/#!msg/mitappinventortest/HyitZbwMJOA/2hYC_Z3K1tQJ

Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

sghughes

unread,
Jul 28, 2015, 10:47:13 AM7/28/15
to MIT App Inventor Forum, taifu...@gmail.com
I had actually spotted your DoSomething example prior to posting on here, unfortunately it isn't the use of the clock which is complicated, it is breaking up my code in a way that this will work.

I've sort of done it, it doesn't work as well in some ways but I do get the text update to let the user know what is going on now. Thanks for the suggestion - but I still hope AI will get a block which allows the housekeeping to run while waiting for something to happen...
Reply all
Reply to author
Forward
0 new messages