New feature: CallSubDelayed - simplifies programs with multiple services / activities

Erel

B4X founder
Staff member
Licensed User
Longtime User
Basic4android v2.0 will include a new set of keywords named: CallSubDelayed, CallSubDelayed2 and CallSubDelayed3.

CallSubDelayed is a combination of StartActivity, StartService and CallSub. Unlike CallSub which only works with currently running components, CallSubDelayed will first start the target component if needed. CallSubDelayed can also be used to call subs in the current module. Instead of calling these subs directly, a message will be sent to the message queue. The sub will be called when the message is processed. This is useful in cases where you want to do something "right after" the current sub (usually related to UI events).

CallSubDelayed will remove the need to store temporary values in process global variables and then read them from Service_Start or Activity_Resume.

With CallSubDelayed the internal framework takes care of starting the target module (activity or service) if needed and waiting for it to be ready. If the target module cannot be started (for example the user has turned off the screen, so the activity cannot resume) then the call will wait in a special queue and will be processed when the activity resumes.

CallSubDelayed works by sending a message to the main message queue. This means that the sub will not be called immediately. The code will continue to execute and when the thread is free to handle messages it will call the sub.

CallSubDelayed2 and CallSubDelayed3 are similar to CallSubDelayed. They work with subs that expect one or two arguments.

CallSubDelayed keywords will make it much simpler and cleaner to work with services and multiple activities.
 

myriaddev

Active Member
Licensed User
Longtime User
Thank you Erel

For these changes in v2.0, I will gladly rewrite my massive coded past project! Thanks, Jerry
 
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
More Information

I'm trying to understand the implications and potential implementation of this feature so please bear with me [• verb (past bore; past part. borne) 5 manage to tolerate; endure: ]


Hypothetical :::
I'm in an activity "MainScreen" lets call it Alpha..

Before the UI elements get created (no Layout for this, views are dropped programmatically) I need to harvest various lists from a web service, there several webservice calls lets say wsCall1, wsCall2 and wsCall3

these need to complete their run, return their data IN ORDER as wsCall3 needs the results from 1 & 2 to process correctly... ALL before
I can begin to flesh out the UI elements as they require the harvested data as well.

As a matter of fact their creation is actually determined by the results from one of the web service calls

This CallSubDelayed doesn't help me in this scenario does it ?

I cannot wait for it to go do its work after my sub (Activity_Create) ends because I need the results in order to continue. Correrct ?!?!?

Perhaps I misunderstand. Can someone please describe.. like I have attempted to here, a practical use for this CallSubDelayed?

And please do correct me if my assumption regarding the use of this feature for my hypothetical scenario is incorrect.

Thank you .
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
They are not really related. StartActivityForResult is a Java keyword that is similar to StartActivity. The difference is that the target Activity is expected to return a result.

CallSubDelayed is a convenient method to start an activity (or service) if needed and call a sub (with optional arguments). This is the simplest way to pass information between activities and services. You do not need to use process global variables and you do not need to check anything in Activity_Resume.
 
Upvote 0

urikupfer

Member
Licensed User
Longtime User
hi erel ,can i call another activity and a sub in this activity , and when the other activity is finished , the sub is executed?
 
Upvote 0

GaNdAlF89

Active Member
Licensed User
Longtime User
When I call this function "CallSubDelayed2(Main, "RefreshData") from another activity, the Main activity get the focus...there is any way to execute RefreshData without return to Main activity? like in backgroud..
Thanks
 
Upvote 0
Top