Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>You should set the tag to an object, not a method.</strong> </p> <p>By setting the tag to <code>getActivity()</code>, you are asking Volley to use a dynamic method call on the main thread as a reference to the request which is happening on a background thread. </p> <p>So when the background thread is trying to cancel the requests, the activity could already be dead.</p> <hr> <p>Rather than using <code>getActivity()</code>, use <code>this</code> or some other object or string. </p> <p>This is good practice for any Tag, and you should also beware of <strong><em><a href="http://www.curious-creature.org/2008/12/18/avoid-memory-leaks-on-android/">leaking your activity.</a></em></strong></p> <p><strong>Solutions:</strong></p> <hr> <p>You could use the current object:</p> <pre><code>request.setTag(this); </code></pre> <hr> <p>or, the static class object</p> <pre><code>request.setTag(MyFragment.class); </code></pre> <hr> <p>or, as a constant in a separate class:</p> <pre><code>request.setTag(CustomTags.LIST_REQUESTS); </code></pre> <hr> <p>CustomTags.LIST_REQUESTS being the best in my opinion (less chance of leaking activity)</p> <p>Something like this:</p> <pre><code>public class CustomTags { public static final String LIST_REQUESTS="CustomTags:LIST_REQUESTS"; } </code></pre> <p><strong>Update</strong></p> <p>I just noticed I was making a mistake in tagging my requests in Volley (though the solutions I posted above are fine). </p> <p>I still thought I would update here an important thing to keep in mind. Volley tags by <strong>identity</strong> not <strong>value</strong>.</p> <p>Thus, it is important to keep in mind that a tag that is merely the same string value, and not the same object itself, will not be recognized as the same <code>tag</code>.</p> <p>It's similar to the difference between</p> <pre><code>String a1 = "A"; String a2 = "A"; a1 == a2; //evaluates to false String a1 = "A"; String a2 = "A"; a1.equals(a2); // evaluates to true </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload