Setting Request Priority Volley

前端 未结 2 865
夕颜
夕颜 2021-02-13 15:38

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         


        
相关标签:
2条回答
  • 2021-02-13 15:55

    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;
            }
        };
    
    0 讨论(0)
  • 2021-02-13 15:56

    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.

    0 讨论(0)
提交回复
热议问题