Getting Progress IntentService

I am working on an Android application that requires many API calls. I created a system that implements a queue system based on IntentService. The thing is, I want to show an accurate update of the ProgressBar while the IntentService is running.

One way is to change the queue system to the AsyncTasks series. I would need to show progress using onProgressUpdate() .

Another way would be to configure the IntentService and get the progress from the background thread.

The fact is that I would like to combine the interesting functions of IntentService and AsyncTask: create a queue system that easily handles user interface events. Is there a better way to implement this?

EDIT: I used AsyncTasks instead of IntentServices. Nevertheless, if someone has a good template for sharing updates with IntentService, feel free to add your comment.

+4
source share
2 answers

I'd

  • run HandlerThread and the handler
  • Get the handler for the main user interface thread.
  • Post work to a background thread using this thread handler
  • update execution results and results in the user interface using the user interface thread handler

That way, you can have one background thread to process your work queue and put whatever you like back into the user interface thread without doing any broadcasting

+2
source

With me, for IntentService, I was thinking about broadcasting when the progress bar started and when the progress bar ended. You can usually use the standard β€œbacktrack” for the end part. You can record different intent broadcasts with different lines.

The tricky part was figuring out a way to call, to find out if the execution line was canceled, and I thought about the status table being updated as the REST call progresses. The table will have a call identifier, and after that the record will be deleted. The table will track if the stream should be active.

So, the REST thread will check the table before each send and stop all / ignore the data sending if it detects a cancellation

+1
source

All Articles