0

This is how i am passing array of custom data type Items ** Items[] itemsArr ** to intent

Intent pruchadeDetails = new Intent(getApplicationContext(),PurchaseHistoryDetails.class);
pruchadeDetails.putExtra("item",itemsArr[position].getShoppingItems());
startActivityForResult(pruchadeDetails, 0);

unable to retrive it using both methods

Item[] itemArr = (Item[])getIntent().getSerializableExtra("item"); //method 1
String json = pruchadeDetails.getStringExtra("item");//method 2

any help is highly appreciated thanks

Shoaib Ahmed
  • 747
  • 12
  • 28
  • http://developer.android.com/reference/android/os/Bundle.html In Android `Serializable` is not recommended, use `Parcelable`. – m0skit0 Jan 30 '13 at 12:24

6 Answers6

1

Hope this code help you.

    intent.putCharSequenceArrayListExtra("ListName", ArrayList)
    Intent purchaseDetails= new Intent(getApplicationContext(), PurchaseHistoryDetails.class);
    purchaseDetails.putCharSequenceArrayListExtra("items", yourArrayList);
    startActivityForResult(purchaseDetails,0);

Pass there Array List of your Custom Data Type.

Pradeep Kumar
  • 777
  • 6
  • 21
1

Try this code

 intent.putCharSequenceArrayListExtra("ArrayListName", ArrayList)
Intent purchaseDetails= new Intent(getApplicationContext(), this.class);
purchaseDetails.putCharSequenceArrayListExtra("items", ArrayList);
startActivityForResult(purchaseDetails,0);
Noman
  • 4,049
  • 10
  • 38
  • 59
0

Make your custom item parcelable and then put the array as a Parcelable array in a Bundle, to pass it to the activity.

takecare
  • 1,684
  • 3
  • 21
  • 32
0

You need to have look at this

http://developer.android.com/reference/android/os/Parcelable.html

Make your Model Parcelable. An example is given in the link.

Usama Sarwar
  • 8,922
  • 7
  • 54
  • 80
0

If you want to do this in-memory, three solutions come to my mind:

  1. Make your data parcelable as described, e.g., by @takecare. See also http://developer.android.com/reference/android/os/Parcelable.html
  2. Use JSON to serialize your data. See, e.g., http://developer.android.com/reference/org/json/JSONTokener.html
  3. Use a singleton class as a holder for your data. You can also use the application object. See, e.g., Singletons vs. Application Context in Android?
Community
  • 1
  • 1
Dan
  • 1,539
  • 12
  • 23
0

For First activity use below.

List<String> itemList = new ArrayList();
for(int i=0;i<5;i++){
itemList.add("i'th List"+i);
}

Intent intent= new Intent(this,ReportsActivity.class);
intent.putStringArrayListExtra("items", (ArrayList<String>) itemList);
startActivity(intent);

And get this array to another activity using

Bundle bundle = getIntent().getExtras();
    List<String> itemList= bundle.getStringArrayList("items");

    for(int i=0;i<itemList.size();i++){
       Log.i("TAG", itemList.get(i));       
    }
user1621629
  • 765
  • 7
  • 19
  • Review this link. [Pass Custom Object](http://stackoverflow.com/questions/2736389/how-to-pass-object-from-one-activity-to-another-in-android) – user1621629 Jan 31 '13 at 06:12