in notepad/app/src/main/java/com/example/android/notepad/NoteEditor.java [214:231]
protected void onPause() {
super.onPause();
// The user is going somewhere, so make sure changes are saved
String text = mText.getText().toString();
int length = text.length();
// If this activity is finished, and there is no text, then we
// simply delete the note entry.
// Note that we do this both for editing and inserting... it
// would be reasonable to only do it when inserting.
if (isFinishing() && (length == 0) && mCursor != null) {
setResult(RESULT_CANCELED);
deleteNote();
} else {
saveNote();
}
}