Android AsyncTask and SQLite DB instance

后端 未结 3 1502
温柔的废话
温柔的废话 2020-12-23 23:50

I have a problem and I am not sure how to approach it. An activity in my app has multiple AsyncTasks which access single SQLiteOpenHelper. I initia

3条回答
  •  我在风中等你
    2020-12-24 00:25

    It is good to use a single DB Helper. The problem is that when the user leaves the Activity the DB is closed but the AsyncTask may still run. So you should check that the DB is not null when you are trying to access it, and if it is null this may mean that your Activity was destroyed and cancel that task.

提交回复
热议问题