java.lang.OutOfMemoryError:pthread_create(1040KB堆栈)失败:再次尝试凌空

时间:2016-03-29 03:52:45

标签: android exception android-volley

嗨,我在使用凌空的服务器发生通信时遇到了这个问题。我附上了与服务器进行通信的代码。请帮助我

SharedPreferences ciuidpref = context.getSharedPreferences(Utility.CIUIDFILENAME, 0);
        SharedPreferences pref = SuiteApplication.getAppContext().getSharedPreferences(Utility.CLOUD_COMM_PREF, 0);
        if (!pref.getBoolean("rbDisable", false) && pref.getBoolean("rbTenMin", true)) {
            RequestQueue mRequestQueue;
            Cache cache;
            if (lockService.context != null) {
                cache = new DiskBasedCache(Service.context.getCacheDir(), 1024 * 1024); // 1MB cap
            } else {
                cache = new DiskBasedCache(SuiteApplication.getAppContext().getCacheDir(), 1024 * 1024); // 1MB cap
            }
            Network network = new BasicNetwork(new HurlStack());
            mRequestQueue = new RequestQueue(cache, network);
                mRequestQueue.start();

            String requestedUrl = Utility.mPINGSERVICE_URL + Utility.getCIUIDValue(context) + "&UniqueIdentifier=" + Utility.getUIDValue(context);
            StringRequest stringRequest = new StringRequest(Request.Method.GET, requestedUrl, new Response.Listener<String>() {
                @Override
                public void onResponse(String responseFromServer) {

            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError errorResponse) {

                }
            });
            mRequestQueue.add(stringRequest);
            stringRequest.setRetryPolicy(new DefaultRetryPolicy(5000, 2, 2));
        }
  

在此请求之后,如果从服务器获得响应,我再次尝试使用volley与服务器通信。那个ack代码附在下面,

private void sendAcknowledgePingService(final CommunicationInterface interfaceReference, final String initialPingResponse) {
        String requestedUrl = Utility.mPINGSERVICE_URL + Utility.getCIUIDValue(context) + "&UniqueIdentifier=" + Utility.getUIDValue(context) + Utility.mPING_ACK;
        StringRequest stringRequest = new StringRequest(Request.Method.GET, requestedUrl, new Response.Listener<String>() {
            @Override
            public void onResponse(String responseFromServer) {


            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError errorResponse) {

            }
        });
        ((SuiteApplication) SuiteApplication.getAppContext()).addToRequestQueue(stringRequest);
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(5000, 2, 2));
    }

使用两个请求队列是否有任何问题?

1 个答案:

答案 0 :(得分:0)

最可能的原因是,您收到的字符串大小超过了保存数据的字符串最大容量限制,您是否会告诉我您尝试获取的数据大小。