Android Question execution flow

Stern0m1

Member
Licensed User
Is there ever 2 portions of code being executed simultaneously? If an event is raised in middle of execution some code in a sub will that event immediately be processed simultaneously, is the sub stopped, or is the sub finished and the event processed?

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Good question. The answer is no. Your code is always executed on the main thread (unless you use a library such as the Threading library).

If an event is raised in middle of execution some code in a sub will that event immediately be processed simultaneously, is the sub stopped, or is the sub finished and the event processed?
The next event will only be executed after the thread finishes executing the code and is free to handle the message queue.
 
Upvote 0

Stern0m1

Member
Licensed User
I'm not familiar with android app development other then B4A.
thread finishes executing the code
"The code" means the code in a sub or is there some other way its broken down in the android system?

Thanks
 
Upvote 0

frasc

Member
Licensed User
How is this handled in the case of a service running at the same time? If an event is raised in a service, is it simply added next in line to the same queue?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
"The code" means the code in a sub or is there some other way its broken down in the android system?
Example:
B4X:
Sub Button1_Click
 'do something
 For i = 1 To 100
 CallAnotherSub(100)
 Next
End Sub
No event will be raised until Button1_Click completes.

How is this handled in the case of a service running at the same time?
There is nothing special about services. The code is executed by the main thread and behaves exactly like code in any other module.
The only difference is that the the service itself is never paused.
 
Upvote 0

SteveTerrell

Active Member
Licensed User
Longtime User
Example:
B4X:
Sub Button1_Click
'do something
For i = 1 To 100
CallAnotherSub(100)
Next
End Sub
No event will be raised until Button1_Click completes.


There is nothing special about services. The code is executed by the main thread and behaves exactly like code in any other module.
The only difference is that the the service itself is never paused.

In other words, subs will never be preempted.
 
Upvote 0
Top