-1

This is my code as it is but how would I go about taking the data to another activity. I would like it to display all the information. any help will be greatly appreciated.

    try {
        JSONArray ja = new JSONArray(result);
        JSONObject jo;

        data = new String[ja.length()];
        ArrayList<String> LectureArray = new ArrayList<String>();

        for (int i = 0; i < ja.length(); i++) {
            jo = ja.getJSONObject(i);
            data[i] = jo.getString("LectureName");

            Log.i("log_tag", "ID: " + jo.getString("ID") +
                    ", CourseCode: " + jo.getString("CourseCode") +
                    ", LectureName: " + jo.getString("LectureName") +
                    ", LectureQuestion: " + jo.getString("LectureQuestion")
            );
        }
  • Use parcelable to pass the complete object instead putting each string and then passing it. Check this [link](http://stackoverflow.com/questions/10107442/android-how-to-pass-parcelable-object-to-intent-and-use-getparcelable-method-of) – Abid Khan Apr 04 '17 at 14:58

3 Answers3

0

You have different ways. You can use extras in the Intent, like this:

startActivity(new Intent(Activity1.this,Activity2.class).putExtra("CourseCode",1234).putExtra("LectureName","lecture1");

You can also create a parcelable object and send it as an extra too

I prefer to use Realm for persistent data which you can access everywhere

Diogo Rosa
  • 756
  • 1
  • 5
  • 24
0

You can use an Intent.

Send:

Intent i = new Intent(this, ActivityReceive.class);
i.putExtra("DATA", data);

Receive (In ActivityReceive):

String data;
if (savedInstanceState == null) {
    Bundle extras = getIntent().getExtras();
    if(extras == null) {
        data = null;
    } else {
        data = extras.getString("DATA");
    }
} else {
    data = (String) savedInstanceState.getSerializable("DATA");
}
Marco Ferraioli
  • 152
  • 1
  • 4
  • 18
0

//To pass object of List:

intent.putExtra("MyClass", obj);

// To retrieve object in second Activity

getIntent().getSerializableExtra("MyClass");