The while loop problem

I need a function to turn a text into a string of hex utf8 bytes. I solved the conversions with javascript. The function must wait for return data from the script. For this I used a while loop block. I think the blocks are correct, so why doesn't the loop end? It seems the "webviewstring" block is not work in looping? I will add that the script itself and returning values to appinventor without a loop work fine.

test_java.aia (3.4 KB)

you are trying to solve an asynchronous processing in a synchronous way, which will not work
rather than a while loop use the WebViewStringChange event to get the result of the conversion

also the correct path to the html file would be http://localhost/test.html

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

Reading data from bluetooth works like this, so I thought it would also work. WebViewStringChange will not work for on-the-fly conversion. This function is to be used to convert data in many text fields and variables and it will be difficult to do asynchronously.

store the textbox component in a global variable, then start the conversion and in the WebViewStringChange event set the result to the text property of the previously stored component, you can use an advanced block for that...
Unbenannt

EDIT: I just have seen, you are already using this technique here

Taifun

Yes. I coped with converting from any variable to text box. Now he is trying to do something similar but the other way. From a text box to any variable. Unfortunately, variables cannot be manipulated like components.

Is it possible to do java scrypt synchronously in appinventor? Is it possible to make an extension from java script? Is there an online environment where I can practice building extensions? I wouldn't have to install additional programs on my computer.

I don't think so...

no, but what about using Java?

you might want to try the

more information about how to create an extension see the App Inventor Extensions document
however that will be more advanced and will require some Java skills...

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

You can't do what you want here because of how Android apps interact with the WebView. When you evaluate some JavaScript, it's passed to another process running Chrome (or the Android System WebView in earlier versions of Android). That code executes asynchronously in that environment and when it is finished the return value is posted back to your app's main thread. Because the blocks run on the main thread, your loop is keeping the thread occupied so it can't process the message with the return value until you've finished blocks execution. Hence, this loops infinitely. There is the WebViewStringChange event that you can use to perform additional behavior once the string has been updated from your JavaScript.