Android Question Service: Use CallSub or CallSubDelayed?

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

following setup:
A Main Activity starts a Service.
In the Main Activity a Sub is defined which is to be called from a Service Sub to update data collated by the service.

Question:
Should the Main Activity Sub be called via CallSub or CallSubDelayed from the Service?
 

udg

Expert
Licensed User
Longtime User
Hi Rob,
according to its tutorial, CallSubDelayed should be the preferred method.
I guess that it depends on the fact that CallSubDelayed is able to "bring to life" the Activity before calling the sub.

udg
 
Upvote 0

udg

Expert
Licensed User
Longtime User
If there are multiple activities then it might be better to use CallSub, to avoid starting the Main activity unintentionally.
@Erel : do you mind to explain that a bit deeper? Both CallSub and CallSubDelay reference the module containing the to-be-called sub, so in which cases Main could be called unintentionally? I am surely missing the point..
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Perhaps he means that you could have a different activity on and you do not want to stop its execution because of the opening of the Main.
In the case of data retrieved from Internet or from a database, perhaps it is better that the Service put that data in a "global container". This perhaps is best also to keep separate data and GUI.

[I have to start fiddling with Services, sooner or later :D]

[Ops... I did it; I'm using a Service in my app but now I use it automatically]
 
Last edited:
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Thanks all for advice.
Using following (pseudo code): with a MainActivity and ServiceModule
B4X:
MainActivity.StartService(ServiceModule)
    ServiceModule.CollateData (interval)
    ServiceModule.CallSub(MainActivity.DisplayData) [if MainActivity is not paused]
MainActivity.DisplayData
Background
Developing of a B4A GoogleMaps Way Tracker (for personal use) using GPS, GoogleMaps Library, KeyValueStore (to store each Track (as a Type) including waypoints), ListView (listing the Tracks, click on a Track the way is displayed on GoogleMaps - data taken from KeyValueStore), long click to delete a Track... and more ...

Good learning moments so far ;) - the B4A UserGuide is essential to read (take time to do so).
 
Last edited:
Upvote 0
Top