1

I had a object list in my activity and i want to pass that object list to another activity to generate a list view in that activity,is it possible?

For simple string values i had used the following code...

Intent intentprint=new Intent(OrdersScreen.this,PrintTemplate.class);
        String pbal=String.valueOf(Balance.getText());
        intentprint.putExtra("Branch", bname);
        intentprint.putExtra("Party", pname);
        intentprint.putExtra("Balance",pbal);
        intentprint.putExtra("Billvalue", bal);
        startActivity(intentprint);

Any help will be appreciated..

golla raghu
  • 39
  • 1
  • 7
  • possible duplicate of [How to send an object from one Android Activity to another using Intents?](http://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-using-intents) – kiranpradeep May 23 '15 at 13:23
  • A similar question is asked here, please take a look at it. http://stackoverflow.com/questions/14333449/passing-data-through-intent-using-serializable/28673100#28673100 –  Jul 28 '15 at 14:53

3 Answers3

1

You can send arralist of objects as below

intent.putParcelableArrayListExtra("some_key", (ArrayList<TYPE>) list);
startActivity(intent); 

Retrieve it

ArrayList<TYPE> list = (ArrayList<TYPE>)getIntent().getParcelableArrayListExtra("some_key");
amodkanthe
  • 4,345
  • 6
  • 36
  • 77
  • yeah but will suggest use ArrayList – amodkanthe May 23 '15 at 13:26
  • By using the above i am getting an error like thisThe method putParcelableArrayListExtra(String, ArrayList extends Parcelable>) in the type Intent is not applicable for the arguments (String, List – golla raghu May 23 '15 at 13:29
  • Make sure your class implements Serializable – amodkanthe May 23 '15 at 13:31
  • use arraylist instead of list – amodkanthe May 23 '15 at 13:37
  • I had written complete funtionality based on List,now its difficult to change to Arraylist.Is there any option to convert List to ArrayLIst... – golla raghu May 23 '15 at 13:40
  • have you tried with List instead of arraylist look for this example http://aryo.lecture.ub.ac.id/android-passing-arraylist-of-object-within-an-intent/ – amodkanthe May 23 '15 at 13:47
  • 1
    I had converted my List into ArrayList but it was showing some error like this,The method putParcelableArrayListExtra(String, ArrayList extends Parcelable>) in the type Intent is not applicable for the arguments (String, ArrayList) – golla raghu May 25 '15 at 05:57
  • why there is extend parceble it should be like this intent.putParcelableArrayListExtra("some_key", ArrayList list); – amodkanthe May 25 '15 at 06:38
  • or just send as intent.putParcelableArrayListExtra("some_key", list); – amodkanthe May 25 '15 at 06:44
  • Based on your inputs i just pass ArrayList> from one activity to another and get succeded for my requirement – golla raghu May 25 '15 at 10:10
1

The similar question was already asked, please take a look at this: Passing data through intent using Serializable

The only difference is the way of storing the object. The above mentioned method uses Serializable.

Community
  • 1
  • 1
0

You can use

    intent.putParcelableArrayListExtra("list",myStringArrayList);

to pass an arraylist to next activity. See this for more complete details. Help with passing ArrayList and parcelable Activity

Community
  • 1
  • 1
Wahib
  • 85
  • 1
  • 11