You know that Volley creates and supports multiple threads, right?
Increments / contractions are not thread safe. Instead, use something like:
AtomicInteger numberOfReq = new AtomicInteger(0); numberOfReq.incrementAndGet();
Not sure if this is the cause of your problem, but an event, if not, is an error awaiting occurrence.
EDIT:
Setting the value of OffReq as volatile int will not solve the problem.
Volatile does not guarantee atomicity. this only ensures that the next thread for reading the variable will see its exact value after the operations performed on the previous topic.
Now the increment (and decrease) operation is actually a triple:
a = x; b = a + 1; x = b;
If atomicity is not forced into this calculation, for example, using AtomicInteger, nothing will stop another thread, visiting even an unstable field in the middle of such a calculation and basically get rid of the increment in the process.
source share