Reputation: 88
Okay, I know that this is a really weird question, but this is a very weird problem.
What I am making is a note-taking app, and basically the user can create notebooks, and then notes in each notebook. What I am having trouble with is deleting said notes.
Activity Hierarchy: Books(main activity) -> Book -> Note
Basically when you delete a note(which is done from the Note activity), the Note activity finishes, and Book calls an onResume() that looks through the notebook folder, and reloads all of the notes into a ListView. The weird thing is that when the Note activity finishes, you can not see the note in the Book activity. However if you reload it (go to Books and then back), or do anything to call the method to refresh, the note is there again with all of it's data.
Here is the code that I used to delete the note:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Are You Sure?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
File note = new File(Path);
if(note.delete()) {
finish();
} else {
Snackbar.make(edt_note, "An Error Occurred", Snackbar.LENGTH_LONG).setAction("Action", null).show();
}
}
});
builder.setNegativeButton("Cancel", null).create();
builder.show();
note.delete() returns true when run.
As a sidenote, I have permission to delete on these local folders. The code to delete the notebooks runs like a charm:
final AppCompatActivity This = this;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Are You Sure?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
File folder = new File(getFilesDir().getPath() + File.separator + Name);
File[] notes = folder.listFiles();
for(File note : notes) {
note.delete();
}
if(folder.delete()) {
finish();
} else {
Snackbar.make((ListView) This.findViewById(R.id.list_notes), "An Error Occurred", Snackbar.LENGTH_LONG).setAction("Action", null).show();
}
}
});
builder.setNegativeButton("Cancel", null).create();
builder.show();
I'm really stumped on this one, any help would be appreciated.
EDIT:
It won't let me choose my own answer as solved, but I figured it out. Details down below.
Upvotes: 2
Views: 59
Reputation: 88
WOW I'M DUMB! lol
What was happening is that I had a save method in onStop() that was saving the note just as the activity was ending. Whoops!
Upvotes: 1