Android Out of memory exception and ContentResolver.registerContentObserver

662 Views Asked by At

In my activity, I have about 10 ContentObservers registered to the ContentResolver (registerContentObserver). I do it in the onCreate().

When changing between landscape and portrait, the onCreate() is called over and over again (and I want it that way - need to change layouts), but after few tries the app runs out of memory and crashes.

Those observers are not class members so they live in the scope of onCreate().

Any idea anyone?

(When I comment all registrations, I don't have any crashes).

1

There are 1 best solutions below

5
On

after being registered, your observers outlive the onCreate context, since they are referenced in the contentresolver.

You need to unregister your contentObservers before registering new ones.