안드로이드 개발 질문/답변
(글 수 45,052)
NoteEdit.java
---(1)--------------------------------------------------------------------------------------
mRowId = savedInstanceState != null ? savedInstanceState.getLong(NotesDbAdapter.KEY_ROWID)
: null;
if (mRowId == null) {
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID)
: null;
}
populateFields();
----(2)--------------------------------------------------------------------------------------
private void populateFields() {
if (mRowId != null) {
Cursor note = mDbHelper.fetchNote(mRowId);
startManagingCursor(note);
mTitleText.setText(note.getString(
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
mBodyText.setText(note.getString(
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
}
-----(3)---------------------------------------------------------------------------------------
private void saveState() {
String title = mTitleText.getText().toString();
String body = mBodyText.getText().toString();
if (mRowId == null) {
long id = mDbHelper.createNote(title, body);
if (id > 0) {
mRowId = id;
}
} else {
mDbHelper.updateNote(mRowId, title, body);
}
}
위와 같이 (1),(2),(3) 군데 인데요..
대략적으로 노트패드 예제를 읽어보긴했는데
세이브스테이트에 만약에 갑자기 에뮬이 종료되거나 꺼질때를 대비해서 세이브스테이트에다가 임시저장한다고 되어있는데
흐름에 대해서 설명좀 부탁드리겠습니다...
NoteDbAdapter 에서
------------------------------------
public Cursor fetchNote(long rowId) throws SQLException {
Cursor mCursor =
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
------------- 왜 굳이 중복제거하고 커서에 넣는건가요?? db에 있는 rowId는 하나일텐데 굳이 중복을 제거하는이유도 궁금합니다..
---(1)--------------------------------------------------------------------------------------
mRowId = savedInstanceState != null ? savedInstanceState.getLong(NotesDbAdapter.KEY_ROWID)
: null;
if (mRowId == null) {
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID)
: null;
}
populateFields();
----(2)--------------------------------------------------------------------------------------
private void populateFields() {
if (mRowId != null) {
Cursor note = mDbHelper.fetchNote(mRowId);
startManagingCursor(note);
mTitleText.setText(note.getString(
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
mBodyText.setText(note.getString(
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
}
-----(3)---------------------------------------------------------------------------------------
private void saveState() {
String title = mTitleText.getText().toString();
String body = mBodyText.getText().toString();
if (mRowId == null) {
long id = mDbHelper.createNote(title, body);
if (id > 0) {
mRowId = id;
}
} else {
mDbHelper.updateNote(mRowId, title, body);
}
}
위와 같이 (1),(2),(3) 군데 인데요..
대략적으로 노트패드 예제를 읽어보긴했는데
세이브스테이트에 만약에 갑자기 에뮬이 종료되거나 꺼질때를 대비해서 세이브스테이트에다가 임시저장한다고 되어있는데
흐름에 대해서 설명좀 부탁드리겠습니다...
NoteDbAdapter 에서
------------------------------------
public Cursor fetchNote(long rowId) throws SQLException {
Cursor mCursor =
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
------------- 왜 굳이 중복제거하고 커서에 넣는건가요?? db에 있는 rowId는 하나일텐데 굳이 중복을 제거하는이유도 궁금합니다..