I am making an app in which I want o pass a json array between 2 activities .how to pass json arry from one activity to another through intents in android. can anybody help me over this?? thanks
Asked
Active
Viewed 3.1k times
2 Answers
59
Intent intent = new Intent(your_activity.this, new_activity.class);
intent.putExtra("jsonArray", mJsonArray.toString());
startActivity(intent);
In the next Activity
Intent intent = getIntent();
String jsonArray = intent.getStringExtra("jsonArray");
try {
JSONArray array = new JSONArray(jsonArray);
System.out.println(array.toString(2));
} catch (JSONException e) {
e.printStackTrace();
}

Lalit Poptani
- 67,150
- 23
- 161
- 242
-
intent.putExtra("jsonArray", mJsonArray.toString()); what is mJsonArray here? – Arjun Singh Jan 18 '17 at 09:16
-
1mJsonArray is the object of JSONArray – Lalit Poptani Jan 18 '17 at 09:38
17
You should convert JsonArray to String then attach it to Intent and send it.
JSONObject jObject = new JSONObject("Your Json Response");
Intent obj_intent = new Intent(Main.this, Main1.class);
Bundle b = new Bundle();
b.putString("Array",jObject4.toString());
obj_intent.putExtras(b);
Where jObject4 is JSON Object.
Get in next Page :
Bundle b = getIntent().getExtras();
String Array=b.getString("Array");

Moji.Michael
- 133
- 1
- 1
- 18

Venky
- 11,049
- 5
- 49
- 66