Setting Request Priority Volley

2019-04-05 12:05发布

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?

2条回答
家丑人穷心不美
2楼-- · 2019-04-05 13:05

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;
        }
    };
查看更多
Ridiculous、
3楼-- · 2019-04-05 13:11

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.

查看更多
登录 后发表回答