android - Communicate progress from local Service -


The application I am creating uses a local service so that files from the Web Can be downloaded for the phone sd card Users can browse the list of books in this app, and read them during online. A user can also download a pdf copy of a book to view offline.

I am using locally bound service to handle the download. I do not want this service to run all the files, only when you download the file so that service stops after completing your tasks, But I am sending the order "code for download" passed through intent to context.startService .

The books available for download are shown in a list. A user can choose to download a book in the list by clicking on their row. On download, I need to show progress by using a ProgressBar on the actual book list row. I also need to show on the lines, if a book is enqueued for download, or if its The download has been completed or failed. Books can be shown in various activities throughout the program - in search, or in the list of user's favorite books, examples For area. When books are shown in different places, these are not the same thing, but they are uniquely identified with their bookId .

Because I do not want to bind service from activity , my temporary plan to include the mapping of bookId on the service class The public static final hashmap was used to download the status, encrypted, downloaded, canceling a enum . The view of each book, if displayed, will check this static Hashmap, and if the Book ID is in the map, retrieve and display its status. I do not particularly like this idea, but at the moment it is the only way I can think of the service without getting bound to get the position and start it.

In addition to this, I need to retrieve the download: progress percentage from a bookId to service , if it is active download then I The activity did not want to be tied in the service, so I'm not sure how to go about recovering the current statute from the service ? My current plan is to use any kind of singleton arbitrator, that can read service to push updates, and ideas, but I am not very happy with this idea.

For this reason I do not want to be compelled by the service from each activity. 1) I am already running another service and 2 .) The binding is verbose and I would like to avoid the need to cross the reference to the service (but this is not too much a problem).

Maybe it is not obligated to set up local service to set up another? Should not I be worried about compelling each activity ? Maybe it's a non-issue?

This is the reason I have the service binding from every activity.) I already have another I'm starting the service

Then consider combining two.

2.) Binding is verbose and

Every activity has its own connection to the service.

Perhaps the local service for binding is not too expensive to warrant this other setup?

Compulsive work dirty for local service is inexpensive.


Comments