Unable to Pass an ArrayList of JSONObjects to new Activity

Viewed 1515

I am having trouble passing an ArrayList<JSONObject> to a new activity.

In my Search activity I use

intent.putParcelableArrayListExtra("data", resultsArray);

But I get a Wrong Argument error.

I used this SO question as a reference. Intent.putExtra List

public class SearchActivity extends AppCompatActivity {

    List<JSONObject> resultsArray;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //other stuff
        resultsArray = new ArrayList<JSONObject>();

    }


    public void goToActivity(){
            Intent intent = new Intent(SearchActivity.this, SearchResultsListActivity.class);
            intent.putParcelableArrayListExtra("data", resultsArray);
            startActivity(intent);
    }

    // ...

}

My SearchResultsListAcivity is just a list

public class SearchResultsListAcivity extends AppCompatActivity {

    public ArrayList<JSONObject> searchResultsArray;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // .. .

        searchResultsArray = getStringArrayListExtra("data");

        ArrayAdapter<JSONObject> adapter = new ArrayAdapter<JSONObject>(this, android.R.layout.simple_list_item_1, android.R.id.text1, searchResultsArray);
        ListView lv = (ListView) findViewById(R.id.listViewSearchResults);
        lv.setAdapter(adapter);

    }
}

I also have toyed with the implmentation answer listed here How to pass ArrayList of Custom objects to new activity?:

Intent intent = new Intent(getApplicationContext(), displayImage.class);            
Bundle bundleObject = new Bundle();
bundleObject.putSerializable("KEY", arrayList);
intent.putExtras(bundleObject);

But again I get wrong argument error.

1 Answers
Related