2013-09-27 3 views
2

발리 소스 코드를 살펴보면 요청의 setSequence 메소드가 쓸모 없다고 보입니다. RequestQueue.add (요청) 방법에있어서, 요청들이 나타내는 것이 줄 것이다 이것으로 첨가 된 원래 순서로 첨가하는 것이 나타난다 :android Volley - Request.setSequence는 쓸모가 없습니까?

request.setSequence(getSequenceNumber()); 

(getSequenceNumber()는 단지 증분 카운터를 반환한다). 요청을 요청할 방법이 있습니까? 아니면 발리를 더 해킹해야합니까?

답변

2

사용 Priority

private Priority mPriority = Priority.LOW; 

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

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

자세한 내용 here.

+0

우선 순위 사용에 대해 알고 있습니다. 그러나 우선 순위를 엉망으로 만들고 싶지 않지만 요청 대기열을 계속 뛰어 넘을 수있는 경우가 있습니다. 단편 A에서 장기 실행 요청이 몇 번 발생하는 경우 사용자가 단편 B로 이동하면 단편 B의 모든 요청을 먼저 처리하고 싶습니다. Priority.HIGH로 설정할 수 있지만 사용자가 C, D, E 등의 조각으로 이동하면 어떻게됩니까? 우선 순위가 없습니다. – StackOverflowed

2

주문을 요청할 수는 없지만 주문을 주문할 수는 있습니다. 이를 위해서는 RequestQueue을 구현해야합니다.

다음은 단일 스레드 실행을 사용하기 때문에 대기열에 추가 한 순서와 동일한 순서로 모든 요청을 실행하는 방법을 보여주는 샘플입니다.

// Copied from Volley.newRequestQueue(..); source code 
File cacheDir = new File(context.getCacheDir(), "def_cahce_dir"); 

String userAgent = "volley/0"; 
try { 
    String packageName = context.getPackageName(); 
    PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); 
    userAgent = packageName + "/" + info.versionCode; 
} catch (PackageManager.NameNotFoundException e) { 
} 

if (stack == null) { 
    if (Build.VERSION.SDK_INT >= 9) { 
     stack = new HurlStack(); 
    } else { 
     // Prior to Gingerbread, HttpUrlConnection was unreliable. 
     // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html 
     stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); 
    } 
} 

int threadPoolSize = 1; // means only one request at a time 
RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network, threadPoolSize); 
queue.start();