Watercayman
Watercayman

Reputation: 8178

Null data when passing ArrayList<Integer> through Intent

I'm sure I've missed something stupid, this can't be this hard...

I'm passing an arraylist of integers from one class to another. Logs show the data is correct in the passing class, but it invariably shows up null in the recieving class. All other intent data is correctly passed.

ArrayList unsavedEditedSets are private class variables.

Please help.

Passing Class segment:

holder.returnButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v)
        {
            unsavedEditedSets.add(setPositionChoice);
            Intent i = new Intent(SetEditor.this, DisplayFullWorkout.class);
            i.putIntegerArrayListExtra("use", unsavedEditedSets); 

            Log.d("INIT - OK",""+unsavedEditedSets); // This shows data is in the arraylist

            i.putExtra("subsets", subsetsList);
            i.putExtras(extras);
            startActivity(i);      
        } 
    });

Catching Class:

private ArrayList<Integer> unsavedEditedSets;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.display_full_workout);

    Intent incomingI = getIntent();
    subsetsList = (ArrayList<HashMap<String, String>>)incomingI.getSerializableExtra("subsets");
    unsavedEditedSets = (ArrayList<Integer>) incomingI.getIntegerArrayListExtra("use");

    extras = incomingI.getExtras(); 

  Log.d("Incoming - BAD",""+unsavedEditedSets); // This shows null arraylist        
}

Tried using a new arraylist right before sending and still get null:

   ArrayList<Integer> test = new ArrayList<Integer>();
   test.add(12);
   test.add(19);
   i.putExtra("use", test); Log.d("INIT - OK",""+test); 

Upvotes: 0

Views: 1032

Answers (2)

QuinnG
QuinnG

Reputation: 6424

Modifying to an answer from my comment on the post:

Simplify the code to only pass along the use extra that's coming through as null. See if that works. If it does; then add back the subsets extra.

It's possible (and based on it working without, likely) that the extras object has an extra in with the key use already.

Another check would be to change the key from use to a new value (not_used_elsewhere_cause_its_really_long) and see if the value is successfully passed through when putExtras is placed back.

Upvotes: 1

JRomero
JRomero

Reputation: 4868

If I recall correctly it should be more along the lines of:

Bundle extras = incomingIntent.getExtras();
ArrayList<Integer>  = extras.getIntegerArrayList("key");

Upvotes: 0

Related Questions