Question

I'm having issues retrieving an ArrayList from one activity to other. My Video class implements Parcelable.

imageView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Bundle b = mVideos.get(numero).getAsBundle();
        Bundle a = new Bundle();
        // putting the parcelable mVideos, which is an array, into the bundle.
        a.putParcelableArrayList("videos", mVideos);
        final Intent i = new Intent("com.video.tv.description");
        i.putExtra("com.video.tv.description", b);
        i.putExtra("com.video.tv.Videos", a); // I added it to intent
        dAct.startActivity(i);
    }
});

How can i retrieve the whole array on the second activity?

Bundle a = i.getBundleExtra("com.video.tv.Videos")?? 

I'm trying to get the whole array as it was before on my initial activity.

Was it helpful?

Solution

dYour code is very strange, it looks like you have a lot of unecessary Bundles and things floating around Try the following when you are constructing your bundle:

imageView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // What is the purpose of this line?
        Bundle b = mVideos.get(numero).getAsBundle();
        Bundle a = new Bundle();
        a.putParcelableArrayList("videos", mVideos);
        // Replace YourNewActivity with the name of the Activity you want to start.
        Intent i = new Intent(dAct, YourNewActivity.class);
        i.putExtra("description", b);
        i.putExtra("videos", a); // I added it to intent
        dAct.startActivity(i);
    }
});

Then, in your receiving activity, do the following to get the list:

Bundle i = getIntent().getExtras();
Bundle a = i.getBundleExtra("com.video.tv.Videos");
ArrayList<Video> videos = a.getParcelableArrayList("videos");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top