I am trying to save some user data internally. Ideally, I would like to save
String[] text;
String name;
String file_name;
Together in one (for lack of a better term) package, and then use all saves name
's with the other data to populate another activities listView, where I can load the saved information. Here is the code I am trying to use to save the information:
Button fileName;
fileName = (Button) findViewById(R.id.save_text);
fileName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
outputStream = openFileOutput(file_name, Context.MODE_APPEND);
ObjectOutputStream phone_save = new ObjectOutputStream(outputStream);
phone_save.writeObject(name);
phone_save.writeObject(text);
Log.i("Save", "Files saved");
} catch (Exception e) {
e.printStackTrace();
}
}
});
Then this is the code that tries to get that saved information(for now I just have it trying to set the text of a text View, not a listView yet)
Button load;
TextView load_text
load = (Button) findViewById(R.id.load);
load.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
fin = openFileInput(file_name);
ObjectInputStream ois = new ObjectInputStream(fin);
String[] Loaded_Text = (String[]) ois.readObject();
ois.close();
load_text.setText(Html.fromHtml(Arrays.toString(Loaded_Text)));
} catch (Exception e) {
e.printStackTrace();
}
}
});
I am having a problem saving and loading the data, no log statement appears when I push the filename button, and nothing appears in the textView when I push the load Button. Essentially none of it works, and I have absolutely no clue how to fix it. I'm sure this code is a mess, but this is really my first time working with storage. Thanks everyone!