0

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); 
9
  • Logs show only: Init - OK [1] and Incoming - Bad null Commented Jul 10, 2014 at 4:10
  • Try to pass as same "subsets" means SerializableExtra. Commented Jul 10, 2014 at 4:11
  • Thank you @Haresh, I originally had it that way and it returned null. Just tried again, just in case... still null. Commented Jul 10, 2014 at 4:14
  • Can you provide the definition of unsavedEditedSets from the catching class? Commented Jul 10, 2014 at 4:24
  • 2
    What if you remove putExtras and putExtra("subsets"...)? Does extras contain "use" by chance? Commented Jul 10, 2014 at 4:52

2 Answers 2

1

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.

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

1 Comment

UPDATE. Nija's answer got me to the solve, and is likely correct for most people with this problem. However, in case someone else makes same mistake, my issue here was that I forgot to implement Serializable in the passing class. This was the direct cause of the null item being passed in the non-serialized list that was passed. Odd way to manifest, and very hard to track. In the end, was indeed my stupid mistake, but not easy to find. Thank you all again.
0

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

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

1 Comment

Thanks J.Romero. Still getting same null incoming... I'd normally blame myself for something stupid, but testing it with the values added directly before the intent seems like it should have worked too...

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.