1

How do I call the ArrayList variable from one class to another class in android? I framed the ArrayList from Json Service, I have tried in many ways, but have a problem with how to call the array list from one class to another class. I using the following code to frame the array list with HashMap:

Shown Below is FirstActivityCLass

protected Integer doInBackground(Void... arg0) {

            try {
                
                JSONObject e = null;
                System.out.println("In Background...");
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                        .detectAll().penaltyLog().build();
                StrictMode.setThreadPolicy(policy);
                String API = "http://traininglabs.com/nic/a-remainders-list.php?email="+email;
                System.out.println(API);
                JSONObject loginjson = JSONfunctions1.getJSONfromURL(API);
                responseArray=loginjson.getJSONArray("user");
                
                mylist=new ArrayList<HashMap<String,String>>();
                for (int i = 0; i < responseArray.length(); i++)
                        {
                    map = new HashMap<String, String>();                     

                JSONObject obj= responseArray.getJSONObject(i);

                    **String ss = obj.getString("id");
                    map.put("id", obj.getString("id"));**
                    map.put("state", obj.getString("status"));
                    map.put("entity", obj.getString("company"));
                    map.put("date", obj.getString("adate"));
                     s1 = e.getString("state");
                     s2 = e.getString("entity");
                     s3 = e.getString("date");
                    System.out.println("this is string--->" + ss);
                    mylist.add(map);
                }

            } catch (Exception e) {
                Log.d("Error", "Error in API" + e.getStackTrace().toString());
                return 1;
            }
            return 0;
        }

This my Second Activity parameter of ArryaList is id

protected Integer doInBackground(Void... arg0) {

            System.out.println("In Background...");
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
            .detectAll().penaltyLog().build();
    StrictMode.setThreadPolicy(policy);

            try {
                String ssp_state = sp_state.getSelectedItem().toString();
                String ssp_entity = sp_entity.getSelectedItem().toString();
                String ssp_date = sp_date.getText().toString();
                String ssp_time = sp_time.getText().toString();

                String API = "http://traininglabs.com/projects/nic/a-edit-remainder.php?id="+**id**+ "&email="+ mail_str+ "&sid="+ sp_id+ "entity="+ ssp_entity+datetime="+ ssp_date+ ssp_time;
                System.out.println(API);

                JSONArray loginjson = JSONfunctions.getJSONfromURL(API);

                Log.d(TAG, "JSON_RES" + loginjson);

                return 0;

            } catch (Exception e) {
                Log.d("Error", "Error in API" + e.getStackTrace().toString());
                return 1;

            } // return null;

        }
5
  • Create a singleton class which having arraylist as member variable and add/read from any where.. Commented Nov 18, 2013 at 9:21
  • You can use Global variables developer.android.com/reference/android/app/Application.html Commented Nov 18, 2013 at 9:23
  • @PankajKumar first class is get the values from the webservice, second class is update the the existing value. so only was using two classes. Have any idea's. Commented Nov 18, 2013 at 9:33
  • Create a singleton class... or use Application class as vicky posted a link... Commented Nov 18, 2013 at 9:34
  • @PankajKumar sorry i don't know the what is Singleton class. Commented Nov 18, 2013 at 9:36

1 Answer 1

5

make it global, or put it into a singleton, more complex but persistent way as you are dealing with network share it via shared preferences.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.