1

i'm trying to parse data from one Activity to the Other. The data which i would like to parse are from the following HashMap:

  ImageButton map = (ImageButton) findViewById(R.id.mapbtn);
        map.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               Intent i = new Intent(Locations.this, MapsActivity.class);
                for (final HashMap<String, String> contact : contactList) {
                    String names = contact.get("name");
                    String str = contact.get("street");
                    String post = contact.get("postalcode");
                    String open = contact.get("opening");
                    String entr = contact.get("entry");
                    String age = contact.get("agegroup");
                    String bag = contact.get("background");
                    String prevbild = contact.get("imageurl");
                    String fsk = contact.get("Fsk");
                    i.putExtra("name", names);
                    i.putExtra("postal", post);
                    i.putExtra("street", str);
                    i.putExtra("opening", open);
                    i.putExtra("entry", entr);
                    i.putExtra("agegroup", age);
                    i.putExtra("background", bag);
                    i.putExtra("imageurl", prevbild);
                    i.putExtra("fsk", fsk);

                }
                startActivity(i);

            }
        });

This is working fine, but i dont know how i can get the data at the other activity. I tried the following but it doesnt work:

for (final HashMap<String, String> contact : contactList) {
        String names = getIntent().getStringExtra("name");
        Toast.makeText(getApplicationContext(),names, Toast.LENGTH_LONG).show();
    }

Thanks

Dominik Hartl
  • 101
  • 11
  • Can you try logging the variable `names` in the first activity to make sure it's not an empty string? – Eric O'Connell Jun 02 '17 at 22:39
  • FYI: you can chain multiple `putExtra` calls together like: `i.putExtra("name", names).putExtra("postal", post).putExtra(. . .` – CzarMatt Jun 02 '17 at 22:43
  • try putting them in a bundle, also every iteration in the loop will override the value associated with the given key, so even if you passed the map correctly you will only receive the last one in the other activity – A.Edwar Jun 03 '17 at 00:56
  • Possible duplicate question. See this answer: https://stackoverflow.com/a/4992465/1827254 – Eselfar Jun 03 '17 at 01:17
  • Btw why do you use an HashMap and not a List of object Contact? – Eselfar Jun 03 '17 at 01:17
  • @Eric O'Connel, i logged it and its working – Dominik Hartl Jun 03 '17 at 13:55
  • I am using a Hashmap to get the Data from my Json into my App – Dominik Hartl Jun 03 '17 at 13:56
  • The reason why i would like to parse the data from one to the other activity is that i would like to get the Coordinates from the one Activity and show the coordinates in a map in the other activity – Dominik Hartl Jun 03 '17 at 18:24

0 Answers0