——-UPDATED————————————-
In this class i do the calculations:
...
ArrayList<Double> final_cores =new ArrayList<Double>();
...
public void cores_func(){
double initcores=Double.parseDouble(num_cores.getText().toString().trim());
double half_time=Double.parseDouble(halftimecores.getText().toString().trim());
double ttime=Double.parseDouble(timecores.getText().toString().trim());
double l=Math.log(2)/half_time;
double fcores=initcores*Math.exp(-l*ttime);
for (int i=0;i<=ttime;i++){
final_cores.add(initcores*Math.exp(-l*ttime));
}
//convert ArrayList to double[]
double[] mydata = new double[final_cores.size()];
for(int i = 0; i < final_cores.size(); i++) {
mydata[i] = final_cores.get(i);
}
Intent i=new Intent(this,core_calcs.class);
i.putExtra("value",fcores);
i.putExtra("value2",initcores);
i.putExtra("value3",ttime);
i.putExtra("final_cores",mydata);
startActivity(i);
}
...
and in the linegraph class :
...
private double [] final_cores =new double [100];
public double [] getFinal_cores(){ return this.mydata;}
public void setFinal_cores( double [] final_cores){ this.mydata=mydata;}
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Bundle extras=getIntent().getExtras();
...
double [] mydata = extras.getDoubleArray("final_cores");
setFinal_cores(mydata);
public Intent getIntent(Context context){
...
double []mydata=getFinal_cores();
ArrayList<Double> x =new ArrayList<Double>();
ArrayList<Double> y =new ArrayList<Double>();
// ArrayList<Double> data =new ArrayList<Double>();
//fill x,y values
for (int i=0;i<=10;i++){
x.add(ttime / 10.0 * i);
}
for (int i=0;i<=10;i++){
y.add(initcores + ((mydata[i]) / 10.0 * i));
}
TimeSeries series = new TimeSeries("Decay");
for (int i=0;i<x.size();i++){
series.add(x.get(i),y.get(i));
}
1) Unfortunately for you it does not seem that there is an easy way to pass double ArrayLists. There are two ways you can approach this:
a) You need to create a class that wraps around a double (note: the primitive not the class) and extends Parcelable (guide is here: http://developer.android.com/reference/android/os/Parcelable.html). If this class is called NewDouble, you can use the code below:
b) If you convert the ArrayList to a double[] before putting it in the bundle, you can use getDoubleArray() to a double array.
Quick code to convert an ArrayList to a double array: