0

i have arraylist which have multiple atitude longitude having different

Log.d("try", "in the try");
                    JSONObject jsonObj = new JSONObject(json);
                    Log.d("jsonObject", "new json Object");
                    // Getting JSON Array node
                    matchFixture = jsonObj.getJSONArray(TAG_FIXTURE);
                    Log.d("json aray", "user point array");
                    int len = matchFixture.length();
                    Log.d("len", "get array length");
                    for (int i = 0; i < matchFixture.length(); i++) {
                        JSONObject c = matchFixture.getJSONObject(i);
                        String matchId = c.getString(TAG_MATCHID);
                        Log.d("matchId", matchId);


                        //  hashmap for single match
                        HashMap<String, String> matchFixture = new HashMap<String, String>();
                        // adding each child node to HashMap key => value
                        matchFixture.put(TAG_MATCHID, matchId);

                        matchFixtureList.add(matchFixture);


                        HashMap<String,String>[] stockArr = new HashMap[matchFixtureList.size()];
                        stockArr = matchFixtureList.toArray(stockArr);
                        for(HashMap<String,String> map : stockArr)
                            for(Map.Entry<String,String> entry : map.entrySet()){
                                Log.d("debug", entry.getKey() + ","+ entry.getValue());
                            }
                    }

i have no idea how to send this to MapActivity

public void setdaata(View view){


    Intent intent = new Intent(this, Registration.class);
    String[] myStrings = new String[] {"test", "test2"};
    intent.putExtra("strings", myStrings);
    startActivity(intent);

}

help me please that how to send this and use in MapActivity

Naveed Abbas
  • 220
  • 3
  • 10

1 Answers1

0

You can send ArrayList between activities. But, if the object in array is not primitive data type(like below, MyObject), it has to implement Parcelable.

In current activity

ArrayList<MyObject> list = new ArrayList<>();
list.add(new MyObject(..));
list.add(new MyObject(..));
list.add(new MyObject(..));

Intent intent = new Intent(CurrentActivity.this, TargetActivity.class);
intent.putParcelableArrayListExtra("list", list);
startActivity(intent);

In target activity

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
    Intent intent = this.getIntent();
    ArrayList<MyObject> list = (ArrayList<MyObject>)intent
       .getParcelableArrayListExtra("list");
}

Edit


  • The above approach ideal for passing data when switching activities (Your actual question).
  • If you want to access your fetched json data from every point of app, it must be stored on your device.
  • Easy way of storing json data : Combine gson library and shared preferences. Check this link to get idea
Community
  • 1
  • 1
blackkara
  • 4,900
  • 4
  • 28
  • 58
  • sir can i have values of LatLog values can i recieved that in other activity in such order that show a specific position answer please its my final year project last module – Naveed Abbas Apr 15 '16 at 17:00