5

I've stored ArrayList<Double> on my bean class,

I've the bean class on my main activity,

How to pass the ArrayList<Double> ,from my main activity to another activity.?

My array list is double. how to pass double arraylist ?

surhidamatya
  • 2,419
  • 32
  • 56
RVG
  • 3,538
  • 4
  • 37
  • 64

4 Answers4

15

This one helps you...

public Intent putParcelableArrayListExtra (String name, ArrayList<? extends Parcelable> value)

For more info look at putParcelableArrayListExtra

EDIT:

If you have a double[] then you can use

void putDoubleArray(String key, double[] value) of Bundle class..

Inserts a double array value into the mapping of this Bundle, replacing any existing value for the given key. And pass this bundle to Intent to Other Activity.

Update:2

FirstActivity:

Intent intent = new Intent(this, OtherActivity.class);
ArrayList<Double> listDouble = new ArrayList<Double>();
listDouble.add(1111.00000);
listDouble.add(13331.00000);
intent.putExtra("arraylist", listDouble);
startActivity(intent);

OtherActivity: (Retrieve Double ArrayList)

ArrayList<Double> listDouble = (ArrayList<Double>) getIntent().getSerializableExtra("arraylist");
System.out.println("...serialized data.." + listDouble);
user370305
  • 108,599
  • 23
  • 164
  • 151
  • Hi @user370305 hi. my arraylist is double. could u explain briefly. how to pass double arraylist ? – RVG Jul 25 '12 at 11:35
  • Hi @user370305 i need another help, can we pass the "bean" class from main activity to another activity? – RVG Jul 26 '12 at 06:51
  • hi @user370305 i arise the question here , http://stackoverflow.com/questions/11664210/how-to-pass-bean-class-one-activity-to-another-activity-on-android – RVG Jul 26 '12 at 07:14
  • hi @user370305 do u know the solution for this http://stackoverflow.com/questions/11883879/route-half-way-point-on-android-code – RVG Aug 10 '12 at 05:23
1

Refer below method to pass data from one activity to other

Eg 1

putIntegerArrayListExtra(String name, ArrayList<Integer> value)
putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value)
putStringArrayListExtra(String name, ArrayList<String> value)
putCharSequenceArrayListExtra(String name, ArrayList<CharSequence> value)

Then you can read from you next activity by replacing put with get with key string as argument,eg

myIntent.getStringArrayListExtra("array");

Eg 2

Intent i = new Intent(this,name.class);
Bundle b = new Bundle();
b.putIntegerArrayListExtra(String name, ArrayList<Integer> value);
//b.putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value);
//b.putStringArrayListExtra(String name, ArrayList<String> value);
i.putExtra(String name,b);
startActivity(i);
Andy
  • 123
  • 1
  • 1
  • 12
0

You should consider passing parameters to an other activity though Intent Extras :

Intent.putExtra() 
Vaim
  • 61
  • 1
0

This code will demonstrate that how to pass a double array object to other activity through inent

String [] my_dblArray=new Sting[no];
   //put some value in the array and then pass through intent
Intent intnt=new Intent(this,YourReqActivity.class);            
Bundle bundle = new Bundle();
bundle.putDoubleArray("doubleVal",my_dblArray);  
intnt.putExtra(bundle);
startActivity(intnt);

// At Receiver side put this line of code.

 String [] dblval=Bndl.getDoubleArray("doubleVal");
Pir Fahim Shah
  • 10,505
  • 1
  • 82
  • 81