取消所有凌空请求的Andr​​oidAndr、oid

由网友(想念式。悲傷)分享简介:在一个片段,但显然使用mRequestQueue.cancelAll(getActivity())在上停止方法的时刻i'm当我移动手机从横向到纵向它仍然在返回的要求而作出的数据,但导致崩溃,因为该持有人dosent数据存在了。如何正确做任何样品code?At the moment i´m using mRequest...

在一个片段,但显然使用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.

阅读全文

相关推荐

最新文章