0

I use an ArrayList to store some data and then pass it to the next activity where it is actually required through the .putStringArrayList() method. I use the same process in a couple of places in a my project where it works absolutely fine. However, in this particular case, when I extract it in the receiving activity, it contains null. To be sure, I even displayed the list before sending it, and it did displayed the strings I require. Here is my code for sending the Arraylist:

 for(int i=0; i<AssignmentTitles.size(); i++)
        {
            System.out.println(AssignmentTitles.get(i));

        }
        Intent localIntent;
        localIntent = new Intent(CourseFolder.this, Assignments.class);
        Bundle b=new Bundle();
        b.putStringArrayList("titles",AnnouncementTitles);
        b.putStringArrayList("links",AnnouncementLinks);
        localIntent.putExtras(b);

        startActivity(localIntent);

Here is the receiving activity code:

    AssignmentTitles = getIntent().getStringArrayListExtra("titles");
    AssignmentLinks = getIntent().getStringArrayListExtra("links");
    System.out.println("size: " + AssignmentLinks.size() + "TITLES:");
    for(int i=0; i<AssignmentTitles.size(); i++)
    {
        System.out.println(AssignmentTitles.get(i));

    }
    setListAdapter( new ArrayAdapter<String(Assignments.this,
    android.R.layout.simple_list_item_1,
    AssignmentTitles));

The problem is that I use the exact same code in another part of my project and it works perfectly, what could be the problem?

Insanovation
  • 337
  • 6
  • 21
Saad Rehman
  • 363
  • 1
  • 7
  • 18

2 Answers2

1

Try this way

AssignmentTitles = getIntent().getExtras().getStringArrayList("titles");
        AssignmentTitles = getIntent().getExtras().getStringArrayList("links");
Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77
0

Use Intent.getExtras() to get the Bundle first, then extract your array lists.

Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33