1

I have a list like this,

List< Double> list_r = new ArrayList<Double>();

How can I pass this list from one activity to other ?

user3291365
  • 445
  • 3
  • 14
Ashish Augustine
  • 1,736
  • 4
  • 19
  • 48

6 Answers6

2

How can I pass this list from one activity to other ?

Then Make this list Static just like this:

public static List< Double> list_r = new ArrayList<Double>();

And Access this list in other activity like this:

private List<Double> list_my = ClassName.list_r;

Where ClassName is your Activity which consists (List< Double> list_r).

But make sure I am just showing a way of passing list. But by making List static It will consume memory even after you have finish the use of that arrayList.

Sagar Shah
  • 4,153
  • 2
  • 23
  • 36
1

You could use a double[] together with putExtra(String, double[]) and getDoubleArrayExtra(String).

Or you can use an ArrayList<Double> together with putExtra(String, Serializable) and getSerializableExtra(String) (the ArrayList part is important as it is Serializable, but the List interface is not).

Joseph Earl
  • 23,153
  • 11
  • 75
  • 89
0

use intent.putExtra();

intent.putExtra("array_list", list_r );
Shayan Pourvatan
  • 11,762
  • 4
  • 40
  • 63
Nambi
  • 11,766
  • 3
  • 35
  • 49
0

You may use of bundle how to use: creating bundle and sending over to new activity or save arrayList in shared preferences: http://www.vogella.com/tutorials/AndroidFileBasedPersistence/article.html

Community
  • 1
  • 1
Unii
  • 1,497
  • 14
  • 31
0
intent.putExtra("list",list_r);

now on the other activity in onCreate:

getIntent().getParcelableArrayListExtra("list");
vipul mittal
  • 17,053
  • 3
  • 39
  • 44
0

Convert double to string, and put it in ArrayList.
In the Activity providing the data, use Intent#putExtra():

double double1 = 0.05;
double double2 = 0.02;
ArrayList <String []> list = new ArrayList <String[]>();
list.add (new String [] {String.valueOf(double_1),String.valueOf(double_2)});
Intent i = new Intent (this,YourTargetActivity.class);
i.putExtra("list", list);
startActivity(i);

Then to retrieve, use Intent#getSerializableExtra() and cast to ArrayList :

ArrayList <String[]> list = (ArrayList<String[]>) getIntent().getSerializableExtra("list");
double double1 = Double.parseDouble(list.get(0)[0]) ;
double double1 = Double.parseDouble(list.get(0)[1]) ;
henry4343
  • 3,711
  • 4
  • 20
  • 29