我有JSON,其中包含公交车票信息。我使用齐射从Web服务获取数据。之后,它获取这些总线信息,并通过adapter发送broadcast。同样,某些仿真器设备也会发生此错误。

 android.app.RemoteServiceException: can't deliver broadcast
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)


我意识到,如果JSONArray的长度大于261,则不会运行适配器。然后,我检查JSONArray是否大于261,并发送到261,为什么会出现此问题?而我该如何解决并将所有数据发送到适配器呢?

Bus.java
       私人无效sendRequest(最终字符串拥有者,最终Map头){

        StringRequest stringRequest = new StringRequest(Request.Method.POST, MyConstants.URL + owner,
                new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {

                //   Log.e("AAAA" + owner, response);
                try {

                    JSONObject object = new JSONObject(response);
                    if (object.getString(MyConstants.SERVICE_STATUS).equals(MyConstants.SERVICE_RESPONSE_STATUS_NOTAVAILABLE)) {
                        // servisten gelen cevap not_available ise
                        //// owner
                        sendVoyagesErrorBroadcast(owner, MyConstants.ERROR_NOTAVAILABLE);
                    } else if (object.getString(MyConstants.SERVICE_STATUS).equals(MyConstants.SERVICE_RESPONSE_STATUS_SUCCESS)) {
                        // servisten gösterilebilecek bir sonuç geldiyse
                        JSONArray result = object.getJSONArray(MyConstants.SERVICE_RESULT);
                        if (result.length()>0) {
                            JSONArray resultGoing = result.getJSONObject(0).getJSONArray("going");
                            sendVoyagesArrayBroadcast(owner + MyConstants.DIRECTION_GOING, resultGoing);
                        }

// sendVoyagesArrayBroadcast
private void sendVoyagesArrayBroadcast(String target, JSONArray resultArray_) {

       JSONArray resultArray = new JSONArray();
        if (resultArray_.length()>261)
        {
            for(int i = 0; i < 261; i++) {
                try {
                    resultArray.put(resultArray_.get(i));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            Log.e("resultArray","");

        }
        else
            resultArray=resultArray_;



        Intent intent = new Intent();
        intent.setAction(BROADCAST_TAG + target);

        intent.putExtra("data", resultArray.toString());
    /*if(!target.contains("bus2")){
     Log.e("sendSuccessBroadcast",target);
     intent.putExtra("data", resultArray.toString());
     }*/

        context.sendBroadcast(intent);
    }

最佳答案

这是由于bundlebundle的大小仅限于传递数据。如果您想不带电线传递数据,请使用EventBus,它可以处理足够的数据传输

07-28 00:33