简体   繁体   English

Android AsyncHttpClient post()进入Fragment中的无限循环

[英]Android AsyncHttpClient post() into infinite loop in Fragment

I'm using the android-async-http-1.4.4.jar library, here is what my code looks like, I left out the declaration/implementation of REMOTE_PHP_URL and entityJSON on purpose (assume they are implemented correctly). 我正在使用android-async-http-1.4.4.jar库,这是我的代码,我entityJSONREMOTE_PHP_URLentityJSON的声明/实现(假设它们已正确实现)。

public class SearchFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_search, container, false);

        mFindButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                final AsyncHttpClient client = new AsyncHttpClient();

                //entityJSON and REMOTE_PHP_URL are implemented correctly

                client.post(getActivity(), REMOTE_PHP_URL, entityJSON, "application/json", new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(JSONObject jsonResultObject) {
                        /*Success Code here*/
                    }
                });
            }
        }
    }
}

When it executes client.post LogCat displays: 执行client.post LogCat显示:

dalvikvm GC_FOR_ALLOC freed 1463K, 21% free 6851K/8628K, paused 4ms, total 4ms

over and over again (infinite loop) until I stop the process in DDMS. 一遍又一遍(无限循环),直到我停止DDMS中的过程。 LogCat doesn't display any (red) errors. LogCat不显示任何(红色)错误。

Keep in mind, the above code runs in other activities in my app just fine. 请记住,以上代码可以在我的应用程序的其他活动中正常运行。 I think it may have something to do with the fact that it's running in a Fragment or something to do with the context or both. 我认为它可能与它在Fragment中运行有关,或者与上下文有关,或者两者都有。 I'm new to android, should I be using something other than getActivity() for the context? 我是android的新手,是否应该在上下文中使用getActivity()以外的方法?

I've tried to update to android-async-http-1.4.5.jar but when I do, I can't @Override onSuccess() for some reason. 我试图更新到android-async-http-1.4.5.jar但是当我这样做时,由于某种原因,我无法@Override onSuccess()

Thanks. 谢谢。

I solved it, my PHP file was not returning a proper JSONObject . 我解决了,我的PHP文件没有返回正确的JSONObject I accidentally had left a few echo 's in my PHP file for debugging purposes and forgot to remove them. 我不小心在PHP文件中留下了一些echo以便进行调试,却忘了删除它们。 There was nothing wrong with the client.post statement! client.post语句没有错!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM