Search code examples
androidandroid-intenthashmapextras

How to send a List to next Intent


I want to send this 'list' to the next class(HomeActivity).But i was trying to do it by sending extras but couldn't somebody please help me to fix this

code

protected void onPostExecute(final List<HashMap<String,String>> list) {
                // Get json response status
                 status = "OK";

                 // updating UI from Background Thread
                runOnUiThread(new Runnable() {
                    public void run() {


                        if(status.equals("OK")){

                            int list_size = list.size();

                                        i = new Intent(getApplicationContext(),
                                                HomeActivity.class);
    startActivity(new);
    }
    }
    });
    }

Solution

  • You have to prepare/seralize your list data for example in JSON format and then pass it to intent as string extra

    JSONArray list = new JSONArray(); list.put(new JSONObject().put("id",1).put("name", "placeNmae"));

    intent.putStringExtra("places", list.toString());