Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Request Priority Volley

I am trying to set the priority of my requests using the Volley library in Android. I cant find out how to set the requests priority.

StringRequest request = new StringRequest(Request.Method.GET,"feed URL",volleyListener, volleyErrorListener);
pe.requestQueue.add(request);

Any Ideas on how I would do this?

like image 720
TwistedEquations Avatar asked Jul 14 '13 16:07

TwistedEquations


People also ask

Is volley deprecated?

GitHub - mcxiaoke/android-volley: DEPRECATED.

What is a volley request?

Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster. Volley is available on GitHub. Volley offers the following benefits: Automatic scheduling of network requests. Multiple concurrent network connections.

Is volley asynchronous Android?

Volley is asynchronous which means you can participate on your own time without having to coordinate schedules.


2 Answers

The library unfortunately isn't fully fleshed out yet. To set priority for a request you need to extend the request and override getPriority(). For your example I would create a new class that extends StringRequest and implements getPriority() (and maybe a setPriority() as well, so you can programmatically change priorities in different requests).

private Priority mPriority = Priority.LOW;

@Override
public Priority getPriority() {
    return mPriority;
}

public void setPriority(Priority priority) {
    mPriority = priority;
}

Priority is an ENUM from the Request class.

like image 190
Flynn81 Avatar answered Oct 19 '22 00:10

Flynn81


Heres a quick way to set a priority,

    StringRequest request = new StringRequest(Request.Method.GET,"feed URL",volleyListener, volleyErrorListener) {
        @Override
        public Priority getPriority() {
            return Priority.IMMEDIATE;
        }
    };
like image 33
petey Avatar answered Oct 19 '22 02:10

petey