0

I'm trying to transfer ArrayList between activities, but nothing I've tried works as well.
This was my best shot, but this didn't work either.

I'm calling the external action here:

getComics getComicInfo = new getComics(charName, pageNum);
getComicInfo.execute();
getIntentData()

and here i'm trying to put data, but the problem is due the fact that this is an external action, so I can't shift through activits.

    if(counter == comicInfoObject.length()){

        Log.v("check arr length =>" , Integer.toString(comicList.size()));
        Intent i = new Intent();
        i.putExtra("comicArrayList", (ArrayList<Comics>)comicList);
        }

and here i'm tring to retrive the data, but it doesn't get inside the "if"

public void getIntentData(){
        Intent i = getIntent();
        if(i != null && i.hasExtra("comicArrayList")){
            comicList2 = i.getParcelableExtra("comicArrayList");
            int size = comicList2.size();
        }
    }

first code is where I call an external class that using api and in the bottom line creates the arrayList second code is inside the external class, where I'm trying to pass the arrayList with putExtra
third code is where i'm tring to retrive the data after getIntentData().

Marcus
  • 6,697
  • 11
  • 46
  • 89
Aviv1002
  • 13
  • 4

2 Answers2

0

Pack at the sender Activity

intent.putParcelableArrayListExtra(<KEY>, ArrayList<Comics extends Parcelable> list);
startActivity(intent);

Extract at the receiver Activity

getIntent().getParcelableArrayListExtra(<KEY>);
Green goblin
  • 9,898
  • 13
  • 71
  • 100
0

You need make a Comics class that implements Parcelable, then use put ParcelableArrayListExtrato pass arraylist.

Here is a sample link for Pass data between activities implements Parcelable

However be careful if your array list too big, you could get intent exception, for this case you could think about a static reference to store your array list.

Xcihnegn
  • 11,579
  • 10
  • 33
  • 33
  • Dont use Parcelable, use Serializeable. – Erdinc Ay Feb 13 '15 at 16:31
  • Parcelable is faster than Serializeable, and serialization is an expensive operation you must keep it minimum. And also Serializable is a standard Java interface, Parcelable is an Android specific interface – Xcihnegn Feb 13 '15 at 16:35
  • No is it not, Parcelable is expensive too and is very hard to understand, Serializeable is easy and fast enough. – Erdinc Ay Feb 13 '15 at 16:36
  • @ErdincAy I had an hard time with the Parcelable and didn't succed in the end, mind giving me some guide about Serializeable? – Aviv1002 Feb 13 '15 at 17:24