3

I have an AsyncTask in which I'm running a database query. For this purpose my AsyncTask subclass contains a field of the type ContentResolver. I'm wondering if it's safe to have it or if it will cause memory leaks like in the case of a Context (AsyncTask and Contexts)?

Community
  • 1
  • 1
Bartek
  • 1,327
  • 1
  • 11
  • 22

1 Answers1

1

From here I could see that ContentResolver keeps a reference to the Context which created it (I guess), so you should take care of it like with any Context references.

But anw you can always use a ContentResolver from the ApplicationContext, it's said to be safe to use.

Edit: Or maybe you don't need to store a ContentResolver at all. You can always create one from an existing Context by this constructor. (That constructor even doesn't need a Context, just pass null and it will automatically use the ApplicationContext)

KenIchi
  • 1,129
  • 10
  • 22