보통 Activity
을 처리 할 때 onCreate
에 데이터베이스를 열고 onStop
으로 닫습니다. 탭 작업을 처리 할 때 onResume
에 다른 항목을 추가하고 에 다른 항목을 추가합니다.데이터베이스 닫거나 다시 열기위한 접근 방법
그래서 코드는이 개폐 너무 많은이
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mDB.open();
}
@Override
protected void onResume() {
super.onResume();
mDB.open();
}
@Override
protected void onPause() {
super.onPause();
mDB.close();
}
@Override
protected void onStop() {
super.onStop();
mDB.close();
}
처럼 보인다?
에 동의하면 db 연결이 필요하지 않을 때 항상 닫아야합니다. – Andreas