PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV 2024 → Android Fatal Thread Problem
Android Fatal Thread Problem
Started by John Fligg, Dec., 12 2017 3:09 PM - 4 replies
Posted on December, 12 2017 - 3:09 PM
This ONLY happens with Android. Same code runs on iOS and Windows. Running on an Android A5.

I start a thread:
ThreadExecute("Validate", threadNormal, ValidateLogin)

In the local ValidateLogin procedure I issue this:
STC_ProgMessage = "Logging in Online ..."
RequestUpdateUI()

I have also tried ExecuteUpdateUI()

However, only in Android I get this fatal error message:

"Only the original thread that created a view hierarchy can touch its views"

Yet RequestUpdateUI() attempts to refresh the window in the original thread. If it works in Windows and iOS why not Android but more importantly how do I fix this. It appears to be a Fatal error.

Thx to anyone who can help.
Posted on December, 12 2017 - 3:36 PM
Hi John,

from it's prefix, I'm gathering that STC_ProgMessage is a static FIELD in your window.

An that means that you are trying to mess with the UI from inside a secondary thread.

And that, as explained CLEARLY in the threads help, is a BIG NO NO.

Store your value in a variable, NOT a field, and then your local to the window update code that put that value in a field. Or use the tExecuteMainThread function and pass the value as parameter to a local function that will do the display...

If it currently works in iOS, but SURE that at some point you'll end up with unexplained 'random' errors.... Coming straight from there.

Best regards
Posted on December, 12 2017 - 3:53 PM
Oh thank you Fabrice. I will read the help again. I am sure it said the idea of RequetUpdateUI() was to overcome this exact issue and to be able to update UI in the original thread. I didn't see any mention of variables. Thx.
Posted on December, 12 2017 - 4:25 PM
Thank you so much once again Fabrice. I still don't think the help made it that clear first time. Re reading it and it seems "implied" what to do.

Anyway I used ExecuteMainThread and it seems to work other than the same failure later in the process so will check that out.

Very much appreciated.

John
Posted on December, 12 2017 - 4:53 PM
requestUpdateUI does exactly what is says and is NOT the problem

The problem is the line BEFORE it, where you put by code a value in a field of your UI... THAT is forbidden.