unregister ContentObserver when ContentProvider shuts down

290 Views Asked by At

My ContentProvider contains a ContentObserver. It's easy to register the observer during onCreate(). However, I see no way to unregister it.

From some digging around, it appears the Android cleans up some things when destroying a ContentProvider. Will it also clean up ContentObserver registrations?

public class MyProvider extends ContentProvider
{
  MyObserver observer = null;

  @Override
  public boolean onCreate ()
  {
    observer = new MyObserver ();
    getContext ().getContentResolver().registerContentObserver (uri, true, myObserver);
    return true;
  }
  ... other methods ...
}
1

There are 1 best solutions below

2
Greg Moens On

There's no need to unregister anything in a content provider because content providers are around as long as your app process is. See this similar question, not exactly a duplicate, but will explain more.

Closing the database in a ContentProvider