I have an activity that has a progressbar and the same activity spawns a service , and the service spawns a thread that is processing data and never ends, but it has cycles, I would like to reflect the progress on those cycles (end of work in each iteration of a while(true) loop = 100% then refresh and the same). What should I use?
Share
You have two options:
One
Make your service a foreground service and then you can display progress bar in the Notification area. To display progress bar you might need to look for RemoteViews. This will look like Android Market which display the download progress in the Notification bar.
For details:
Running service in Foreground
How to change Notification Layout
Second
This will be more involving. You have to Bound to the service. The docs here will help. Now they might be saying that Bound Services are not suppose to live for long but it is not mandatory.
In this case, you can use
AsyncTask(if you are not using, in place of thread) in your service. In theonProgressUpdatemethod ofAsyncTaskyou will publish the progress to Service and then Service will publish that to Actual activity using IPC. Below are refs:AsyncTask
Bounded Service
And you might need AIDL for IPC