取消所有凌空请求的Andr​​oid [英] Cancel All Volley Requests Android

查看:123
本文介绍了取消所有凌空请求的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个片段,但显然使用mRequestQueue.cancelAll(getActivity())在上停止方法的时刻i'm当我移动手机从横向到纵向它仍然在返回的要求而作出的数据,但导致崩溃,因为该持有人dosent数据存在了。如何正确做任何样品code?

At the moment i´m using mRequestQueue.cancelAll(getActivity()) at on stop method in a fragment but apparently when i move the phone from landscape to portrait it is still returning the data made in the request but causing crash because the holders for the data dosent exist anymore. any sample code of how to do it properly?

推荐答案

,使全通RequestFilter。

Instead of using a tag for cancelAll, make an all-pass RequestFilter.

mRequestQueue.cancelAll(new RequestQueue.RequestFilter() {
    @Override
        public boolean apply(Request<?> request) {
            return true;
        }
    });

编辑:这将取消所有活动/片段的所有请求,并且不与Activity生命周期毫不逊色工作。管理最好的方法是将字符串标记独特添加到您的片段。

This cancels all Requests from all activities/fragments, and doesn't work favorably with the Activity Lifecycle. The best way to manage this is to add a String tag unique to your fragment.

这篇关于取消所有凌空请求的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆