I'm new to programming.
I saved an array of strings through FileOutputStream.write()
in my MainActivity
.
I can read the array perfectly through FileInputStream
in the Activity itself.
To read this array in another Activity I used the following code:
// READ
FileInputStream fin;
fin = openFileInput("my_file");
ObjectInputStream ois = new ObjectInputStream(fin);
String[] temp = (String[]) ois.readObject();
ois.close();
String texto = temp[5].replace("-", " ");
TextView tv = (TextView) findViewById(R.id.a2);
tv.setText(texto);
Eclipse pointed to the following error:
The method openFileInput (String) is undefined for the type AdapterPages
Then I made the following modification in the code (maybe there is the error):
MainActivity main = new MainActivity();
Context contexto = main.getApplicationContext();
FileInputStream fin;
fin = contexto.openFileInput("my_file");
It works "without errors", but the text of TextView tv
does not change.
UPDATE 1
Save the array :
// WRITE NEW FILE
FileOutputStream fout = openFileOutput("my_file",
Context.MODE_APPEND);
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(mVal);
oos.close();
UPDATE 2
Call the other activity :
// RU call button
public void btTela1(View v) {
startActivity(new Intent(this, Pager.class).putExtra("dados", texto));
}