I saved some Values in the primary activity and I want to load it in the secondary activity but i dont know how to do it. The values are loaded in the same activity. Can anyone help me please.
Thank you very much!
primary activity:
public void SaveList(View view) {
//WriteMethode
String weight = "Gewicht: " +weightText.getText().toString() + "kg" ;
String height = " Körpergröße: "+ heightText.getText().toString() + "cm";
try {
FileOutputStream fileOutputStream = openFileOutput("values.txt",MODE_APPEND);
fileOutputStream.write(weight.getBytes());
fileOutputStream.write(height.getBytes());
Toast.makeText(getApplicationContext(),"Gespeichert",Toast.LENGTH_LONG).show();
fileOutputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void showlist(View view){
try {
FileInputStream fileInputStream = openFileInput("values.txt");
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
BufferedReader bufferedReader= new BufferedReader(inputStreamReader);
StringBuffer stringBuffer= new StringBuffer();
String lines;
while((lines=bufferedReader.readLine()) !=null){
stringBuffer.append("\n"+lines +"\n");
}
resultText.setText( stringBuffer.toString());
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Intent intent = new Intent(this, MyList.class);
startActivity(intent);
}
}
Second activity:
public class MyList extends AppCompatActivity {
TextView resultLabel;
TextView resultText;
// Button listButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_list);
}