2010년 12월 30일 목요일
[Android Course][English][Theme] - DB Query () API uses the wrong
: ContentProvider between the Application is the only way to share data. ContentProvider to store and retrieve the data and allows access from any Application. Usually at this time to have access to Database "Cursor & Query ()" API is used.
=> Here I am 'Query ()' instead, 'managedQuery ()' is recommended for use.
Operating the same, but
managedQuery () write the life cycle of the activity has the advantage that it behaves like.
In other words, cursor.close onDestroy do not call the call automatically when the cursor is a Close.
- "Cursor & Query()" Wrong usage example
Cursor cursor = ContentResolver.query(....................................);
=> After straightening using 'cursor.close ();' If I tell you, leak or dead can happen.
- "Cursor & Query()" Recommended Usage Examples
Cursor cursor = managedQuery(....................................);
In addition, inquiries, or questions, please contact us.
(joonryang@gmail.com)
라벨:
managedQuery,
Query
[Android 강좌][Korean][테마] - DB Query() API의 잘못된 사용
: ContentProvider는 Application들 사이의 데이터를 공유할 수 있는 유일한 방법이다. ContentProvider는 데이터를 저장하고 검색하고, 모든 Application에서 액세스 할 수 있도록 한다. 이 때 Database에 접근하기 위해서 보통 "Cursor & Query()" API를 사용합니다.
=> 여기서 나는 'Query()' 가 아닌, 'managedQuery()' 사용을 권장한다.
동작은 동일하지만,
managedQuery() 를 쓰는 경우 activity 의 life cycle 과 같이 동작한다는 장점이 있다.
즉, cursor.close 를 호출해 주지 않아도 onDestroy 가 호출되면 자동으로 cursor가 Close 됩니다.
- "Cursor & Query()" 잘 못된 사용 예제
Cursor cursor = ContentResolver.query(....................................);
=> 반듯이 사용 후에 'cursor.close();' 를 해주지 않는다면, leak 또는 dead 현상이 발생할 수 있다.
- "Cursor & Query()" 추천 사용 예제
Cursor cursor = managedQuery(....................................);
추가로 문의 사항이나, 궁금한 점이 계시면 연락주세요.
(joonryang@gmail.com)
※ 도움이 되셨다면, ^^. 맨 위 광고클릭 좀..ㅎㅎ
라벨:
managedQuery,
Query
피드 구독하기:
글 (Atom)