You must set the tag for the object, not for the method.
By setting the tag to getActivity() , you will ask Volley to use a dynamic method call in the main thread as a reference to the request that occurs in the background thread.
Therefore, when the background thread tries to cancel requests, the activity may already be dead.
Instead of using getActivity() use this or some other object or string.
This is good practice for any tag, and you should also beware of activity leaks.
Solutions:
You can use the current object:
request.setTag(this);
or, an object of a static class
request.setTag(MyFragment.class);
or, as a constant in a separate class:
request.setTag(CustomTags.LIST_REQUESTS);
CustomTags.LIST_REQUESTS is the best in my opinion (less likely to leak activity)
Something like that:
public class CustomTags { public static final String LIST_REQUESTS="CustomTags:LIST_REQUESTS"; }
Update
I just noticed that I was mistaken in tagging my queries in Volley (although the solutions that I posted above are fine).
I still thought that I would be updating an important thing to keep in mind. Signs of volleyball identity are not meaningful .
Thus, it is important to keep in mind that a tag that is simply the same string value and not the same object will not be recognized as the same tag .
It looks like the difference between
String a1 = "A"; String a2 = "A"; a1 == a2; //evaluates to false String a1 = "A"; String a2 = "A"; a1.equals(a2); // evaluates to true