Progress Bar from within a Service Module

Steven Sparrow

Member
Licensed User
Longtime User
I am looking for some help in displaying and updating progress bar view from within a sevice module?

I have a service module that receives data in background over the Bluetooth serial port using AsyncStreams. When the download begins, I want to display a Progress bar to indicate the status of the download.

With a single Activity module, is easy to us CallSub2() from the Service module to display and refresh the Progress bar View, but now that I have multiple activity modules, I'm looking for a better way to show a progress bar than having to add this view to all activity modules, determine which one is not paused" and call it?

I have tried starting a specific activity, for example, Main using StartActivity() on mny main activity and then CallSub2(), but there may be be a "startup delay" which causes the CallSub2 to be ignored.

Thanks
Steve
 

Steven Sparrow

Member
Licensed User
Longtime User
Thanks Erel,

I was kind of hoping I had missed something... never mind.

I guess I can still try to start a "specific" activity from the service module, set a variable within the activity when it is "ready and visible", which can be tested by the service module. I can then try to to invoke a CallSub to show the progress bar.. or would I be wasting my time ?

Keep up the great work on this excellent product !

Regards
Steve
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Usually you do not want to call StartActivity from a service. The user will be surprised to see an Activity showing from nowhere.

You can store the progress value in a process variable in the service.
Use CallSub to notify the target activity about the update.
The activity will fetch the value from the process variable and update the progress bar.
Now for the important part... Also call this sub from Activity_Resume. This way if the activity was paused it will still show the correct value when it resumes.
 
Upvote 0

Steven Sparrow

Member
Licensed User
Longtime User
Erel,

Thanks for your thoughts; you are a busy guy and I hate wasting your time.

I agree with your points, although the situation is a unusual in our case, because it's part of a golf swing analysis system that wirelessly receives swing data from our device and then refreshes a dashboard type panel. The problem is that the user may leave the "screen" on a Stats page, or other panel but when they next take a swing, we will revert to the Dashboard activity.

Fr nwo it is working, providing I allow a small delay after StartActivity and a CallSub() to that activity.

Thanks for your time and keep up the great work!
Now if only I could port the app to an iPhone....

Steve
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Calling StartActivity sends a message to the message queue. It doesn't start the activity immediately. The message queue is processed when your code finishes executing. This means that calling StartActivity and the CallSub will not work as the activity will still be paused during the call to CallSub. You should use a timer and make the CallSub (I guess that this is what you are already doing). The timer interval can be very short as the timer is also raising events by adding messages to the message queue.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…