There is a JSON
that include bus tickets information. We use volley to get data from web service. After, it get these bus information it send adapter
with broadcast
. Also, it occurs this error with some emulator devices.
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)
I realized if JSONArray is bigger than 261 length, it don't run adapter. Then, I check JSONArray if it is bigger than 261 it send till 261 Why this problem happen? And how can solve this and send all of data to adapter?
Bus.java private void sendRequest(final String owner, final Map header) {
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);
}
This is due to bundle
, bundle
sizes are limited to pass data. Use EventBus
if you want to pass data without a wire, it can handle enough data transfer