2

What's the best way to access the database through an async task?

I don't think I should pass in a reference to the DbAdapter that the activity is using (could be closed as the activity may be garbage-collected).

Also, the db needs a context to be opened and closed, but I don't have that with the async task.

1 Answer 1

1

AsyncTask is an abstract class, so you have to extend it.

Create a class which extends AsyncTask, then in the constructor of this class you can add every things you want like the Context.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.