Sunday, 15 February 2015

Best practices for updating a progress from background service [Android] -


Sorry if I am asking again but I did not find any relevant information for this question.

I am downloading / uploading a file in the background service. I would like to send the file download / upload progress from this service. One method I know is that every 5% or 10% file is to be downloaded / uploaded. Second, to engage the activity with the service, implement an interface, and inform the activity tied to the service, which is downloaded / uploaded to the file. I do not know which method is good if you have some good method, please share with me even 5 can be downloaded / uploaded to the file simultaneously.

Thanks in advance

Note: I am not in the activity, where I started downloading, the user can go back home, can start using some other app , But whenever it comes back, it will be notified with the update File download / progress progress

The best solution is to use the IntentService IntentService class to run an operation on a background thread. A provides a simple structure. This allows you to operate long-running operations without affecting the responsiveness of your user interface. In addition, an intent service is not affected by most user interaction lifecycle events, so an ASCink Task that is running in the circumstances will be closed

But there are some limitations of an intent service:

< Ul>
  • It can not interact directly with your user interface. In order to put your results in the UI, you have to send them to an activity.
  • Work requests run sequentially if an operation is running in an IntentService, and if you send it another request, the request waits until the first operation is finished.
  • An operation that runs on an intent service can not be interrupted.
  • However, in most cases the intent service is the most preferred method for conducting a plain background.

    Note: If your app targets Android 5.0 (API level 21), then you should use Job Scheduler to run background services.


    No comments:

    Post a Comment