Hello i am using SqliteDatabase and i am using a background service to download some data. I have the db to closed onDestroy() method and to open onCreate() and onResume(). When i change the orientation of the phone some times the background service try to save the data into the database when the db is closed because of the orientation change. How i can fix that?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyApplication.getInstance().openDatabase();
}
@Override
protected void onResume() {
super.onResume();
MyApplication.getInstance().openDatabase();
}
@Override
protected void onDestroy() {
super.onDestroy();
MyApplication.getInstance().closeDatabase();
}
This is some of the code of my MainActivity. I have the database to MyApplication class. The service just using MyApplication.getInstance().insert(data); that is insert data into the db. Can i close the database only when the app is closed and not on the orientation change?