nohttp框架的OnResponseListener内存泄漏问题
nohttp框架的OnResponseListener内存泄漏问题
发布时间:2018-02-01 来源:查字典编辑
摘要:不管回调函数里面写了什么,只要页面跳转,LeakCanary就会弹出来内存泄漏。求助大神回复讨论(解决方案)贴代码啊,LogActivity...

        不管回调函数里面写了什么,只要页面跳转,LeakCanary就会弹出来内存泄漏。

nohttp框架的OnResponseListener内存泄漏问题0

求助大神

回复讨论(解决方案)

nohttp框架的OnResponseListener内存泄漏问题1 贴代码啊,LogActivity! HttpUtils.loginRequest(MD5Tool.md5(name), MD5Tool.md5(password), new OnResponseListener< String >() {

                    @Override

                    public void onStart(int what) {

                    }

                    @Override

                    public void onSucceed(int what, Response< String > response) {

                        //根据返回的数据进行判断,如果是判断出登录失败那么吐司,否则跳转

                        //"wrong".equal(response.getString())

                        if (false) {

                            ToastUtils.show("用户名或者密码错误");

                        } else {

                            String json = response.get();

                            User user = new Gson().fromJson(json, User.class);

                            SharedPreferencesTool.saveString(MyApp.getContext(), Constants.ORGCODE, user.getORG_CODE());

                            SharedPreferencesTool.saveString(MyApp.getContext(), Constants.USERTYPE, user.getUSER_TYPE());

                            SharedPreferencesTool.saveString(MyApp.getContext(), Constants.USERCODE, user.getUSER_CODE());

                            SharedPreferencesTool.saveString(MyApp.getContext(), Constants.USERNAME, user.getUSER_NAME());

                            SharedPreferencesTool.saveString(MyApp.getContext(), Constants.ID, user.getID());

                            Log.e("JSON", json);

                            enterHome();

                        }

                    }

                    @Override

                    public void onFailed(int what, Response< String > response) {

                        ToastUtils.show("登录失败");

                    }

                    @Override

                    public void onFinish(int what) {

                    }

                });

HttpUtils.loginRequest(MD5Tool.md5(name), MD5Tool.md5(password), new OnResponseListener< String >() {

                    @Override
                    public void onStart(int what) {
                    }

                    @Override
                    public void onSucceed(int what, Response< String > response) {

                        //根据返回的数据进行判断,如果是判断出登录失败那么吐司,否则跳转
                        //"wrong".equal(response.getString())
                        if (false) {
                            ToastUtils.show("用户名或者密码错误");
                        } else {
                            String json = response.get();
                            User user = new Gson().fromJson(json, User.class);
                            SharedPreferencesTool.saveString(MyApp.getContext(), Constants.ORGCODE, user.getORG_CODE());
                            SharedPreferencesTool.saveString(MyApp.getContext(), Constants.USERTYPE, user.getUSER_TYPE());
                            SharedPreferencesTool.saveString(MyApp.getContext(), Constants.USERCODE, user.getUSER_CODE());
                            SharedPreferencesTool.saveString(MyApp.getContext(), Constants.USERNAME, user.getUSER_NAME());
                            SharedPreferencesTool.saveString(MyApp.getContext(), Constants.ID, user.getID());
                            Log.e("JSON", json);
                            enterHome();
                        }
                    }

                    @Override
                    public void onFailed(int what, Response< String > response) {
                        ToastUtils.show("登录失败");
                    }

                    @Override
                    public void onFinish(int what) {
                    }
                });

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新安卓软件开发学习
热门安卓软件开发学习
编程开发子分类