I’ve got a database singleton and I want to call .close() on it when the app finishes.
I can call .open() on the database in onCreate() in the Application class, but where do I call .close()?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yeah what I do is sort of look for foreground activity. After each foreground activity dies, I can decrement. Once I reach zero and stay there for a reasonable amount of time, I know I am safe to close such resources. Ended up making virtual lifecycle callbacks in my app this way. So this way works no matter how many tasks you have or where things start from. IF you can only run and start your app from one place and everything goes only in a single linear fashion, then yes the root activity approach works too.
Specifically like this:
BaseActivity
MyBaseApplication