2

I am sending large JSON string where records of JSON array length is 800 but currently when I start that Activity then application quits without any crash message but when I reduced the records to 100 then it works perfectly.

I am doing like below

Intent myIntent = new Intent(getActivity(),
        ActivityName.class);
myIntent.putExtra("jsondata", respUserData);
getParentFragment().startActivityForResult(myIntent,
        pick_plan);
getActivity().overridePendingTransition(
        R.anim.lefttorightanim, R.anim.righttoleftanim);

So what it is correct way to send large JSON to next Activity ?

Thanks in advance.

Shiva
  • 6,677
  • 4
  • 36
  • 61
N Sharma
  • 33,489
  • 95
  • 256
  • 444
  • Have you tried using a Bundle to store the data (and attach it to the intent) instead of directly adding data to the intent? – Chnoch Jun 20 '14 at 11:12
  • @Chnoch No I didn't try but let me know does `Bundle` can store large `JSON` ? – N Sharma Jun 20 '14 at 11:14
  • Do you have a sample of your JSONObject available? It should be able to store large amounts of data. – Chnoch Jun 20 '14 at 11:29

3 Answers3

0

Don't pass large String or Large Data directly in to intent, you have to use Application Class. Set variables and methods in application class. To get more information about Application Class view this answer.

Community
  • 1
  • 1
none
  • 176
  • 1
  • 7
0

Since it's probably not a global state that you pass, I advise against using the Application Class. If it is data that you use all the time you can easily store it there.

For passing a large amount of data using the provided way with putExtra() should work fine. Apparently the Bundle doesn't handle your JSONObject correctly. You can try to convert it to a String, pass this to the Intent.putExtra() and then reconstruct the JSONObject from the String. This will have some impact on the performance, but should be usable as a workaround.

Chnoch
  • 772
  • 9
  • 20
  • Yes I am doing same, converted `JSONObject` to `String` but have same problem. So Should I use `Bundle` instead of `Intent.putExtra` to pass large `JSON` string ? – N Sharma Jun 23 '14 at 04:49
  • No, you should be able to use Intent.putExtra() directly, as it also works with Bundles in the background. – Chnoch Jun 23 '14 at 05:57
-1

You can pass values as you mentioned. It will be as a bundle so it can hold large amount of data also. We can pass Arraylist, model classes etc using the intent.

Jiju Induchoodan
  • 4,236
  • 1
  • 22
  • 24