I can read and save a textfile to an Arraylist
with my code. Now I want to use this Arraylist
in other activities but I have problems with passing the Arraylist
to another class. I tried it with intent but it didnt work. I will add the codes of my program below.
Intent intent=new Intent(this, ergebnisse.class);
intent.putExtra("NEFZ", Nlist);
startActivity(intent);
I hope you can help me.
My first activity:
public class NEFZ2array extends AppCompatActivity implements Serializable {
public static void main(String[] args) {
FileReader file = null;
try {
file = new FileReader("NEFZ.txt");
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ArrayList<Double> Nlist = new ArrayList<Double>();
int i=0;
Double d= null;
try {
BufferedReader input = new BufferedReader(file);
String s=null;
while((s=input.readLine())!=null) {
StringTokenizer st = new StringTokenizer(s,",");
while(st.hasMoreTokens()) {
try {
d = Double.parseDouble(st.nextToken());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Nlist.add(i, d);
}
}
input.close();
} catch(Exception e) {
e.printStackTrace();
}
for(double j:Nlist) {
System.out.println(j);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nefz2array);
}
}
My Receiver Activity:
public class ergebnisse extends AppCompatActivity implements Serializable {
public Button button_ausfuerlicher;
public Button button_home;
public void init(){
button_ausfuerlicher = (Button) findViewById(R.id.button_ausfuerlicher);
button_ausfuerlicher.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(ergebnisse.this, ausfuehrlicher.class);
startActivity(intent);
}
});
}
public void init2(){
button_home = (Button) findViewById(R.id.button_home);
button_home.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(ergebnisse.this, MainActivity.class);
startActivity(intent);
}
});
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ergebnisse);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
init();
init2();
}
}