2011-11-21 4 views
1

현재 커서는 아래 그림과 같이 제어됩니다. startManagingCursor() 사용의 이점이 무엇인지 알고 싶습니다. 현재 나는 많은 커서를 가지고 있으며, 모두 알고 있으며, 그때 그들과 관련하여 오류가 발생합니다. 더 나은 실천이 아니라면 이것이 유익 할 것입니다.startManagingCursor() 사용의 장단점은 무엇입니까

Cursor c = db.rawQuery("GENERIC QUERY" , null); 
c.moveToFirst(); 
numval = c.getInt(c.getColumnIndex("_id"));     
c.close(); 

답변

1

모든 startManagingCursor 우선은 API http://developer.android.com/reference/android/app/Activity.html#startManagingCursor(android.database.Cursor)

이제 우리는 LoaderManager와 CursorLoader 클래스를 사용할 필요가 deperecated된다. ans 귀하의 질문에, 활동 커서가 다음 화면 오리 엔테이션이 일어날 때 그것을 최적화 할 수 있습니다. 그리고 능동적으로 커서의 라이프 사이클을 처리합니다. 아래는 android doc의 스 니펫입니다.

This method allows the activity to take care of managing the given Cursor's lifecycle for you based on the activity's lifecycle. That is, when the activity is stopped it will automatically call deactivate() on the given Cursor, and when it is later restarted it will call requery() for you. When the activity is destroyed, all managed Cursors will be closed automatically

0

는 startManagingCursor은 활동 수명주기에 커서 라이프 사이클을 묶어. 여기에는 활동이 다시 시작될 때 자동으로 다시 쿼리가 포함됩니다. 필자는 필자의 작업이 다시 시작될 때마다 쿼리를 다시 실행하지 않아도되기 때문에 사용하지 않는 경향이 있습니다.

모범 사례가 적용되는 한 활동이 일시 중지되었을 때 데이터베이스를 업데이트해야한다고 생각하지만 나 자신의 커서를 관리하는 것이 여전히 부분적입니다. 나는 또한 짧은 시간 동안 커서를 열어 놓는 것을 선호하므로 샘플이 내가 사용하는 패턴과 일치합니다.

관련 문제