AsyncTask Database Access - Where to Initialize, Close?

When accessing a database in AsyncTask , if the database connection must be a member of the parent Activity or open / close in each AsyncTask ?

If the connection is a member of this action, I am concerned that when switching between my application actions, there is a possibility that the database connection may be closed before it finishes using this function.

+4
source share
1 answer

Not what I ever thought about, but instinctively I would make AsyncTask as self-sufficient as possible, i.e. internally handled its own db operations. The same applies to any stream code.

EDIT: Here's a link to a good article that discusses SQLite multiple access in Android ... Android SQLite Locking

+2
source

Source: https://habr.com/ru/post/1345302/


All Articles