2

Hi i am working on an android application. Its a you tube type of application.

I am facing one issue . There is a download feature in my app. When i start downloading some content then during downloading if i will create any another network connection then it will take more time.

For Downloading i used a Asyntask handled by a services.

and for simple network call i used a Asyntask.

Then kindly please suggest me how can i overcome with this problem.

My expectation is if downloading is in progress then if i make some network call then this network call should be on high priority.

Please suggest.

nitin tyagi
  • 1,176
  • 1
  • 19
  • 52

1 Answers1

2

If you are using asynctask, you can attempt setting the priority of the current thread using something like this.

protected void doInBackground() {
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    // download the things
}

Asynctasks are usually lower priority. You can read more about it here:

http://www.androiddesignpatterns.com/2014/01/thread-scheduling-in-android.html


If you are using many HTTP requests, I do however recommend you use a library, like Volley. This allows you to easily set up a request queue, and jump the queue for high priority items.

You can read more about that, here:

http://arnab.ch/blog/2013/08/asynchronous-http-requests-in-android-using-volley/

Jacques.S
  • 3,262
  • 2
  • 21
  • 27
  • HI i have not tried your code , but use Executor and it resolved my issue. but Surely i will try your code also . – nitin tyagi Jan 20 '16 at 06:43