title: restart on application uninstall
body: <p>Using <a href="http://developer.android.com/reference/android/content/pm/PackageManager.html#setComponentEnabledSetting%28android.content.ComponentName,int,int%29" rel="nofollow">setComponentEnabledSetting</a> causes the android os to restart upon uninstall. Has anyone else come across this? </p>
  
  <p>ERROR/AndroidRuntime(1143): <em>*</em> FATAL EXCEPTION IN SYSTEM PROCESS: android.server.ServerThread
          java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.PACKAGE_CHANGED dat=package:com.example.foo flg=0x8000010 (has extras) } in com.android.server.NotificationManagerService$2@41b00228</p>
  
  <p>Caused by: java.lang.IllegalArgumentException: Unknown package: com.example.foo
          at com.android.server.pm.Settings.getApplicationEnabledSettingLPr(Settings.java:2443)</p>
  
  <p>Here's the code : </p>
  
  <pre><code>public class FooActivity extends Activity {
  
      @Override
      protected void onResume() {
          super.onResume();
          enableReceiver();
      }
  
      @Override
      protected void onPause() {
          super.onPause();
          disableReceiver();
      }
  
      private void enableReceiver() {
          setReceiverState(PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
      }
  
      private void disableReceiver() {
          setReceiverState(PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
      }
  
      private void setReceiverState(int receiverState) {
          getPackageManager().setComponentEnabledSetting(new ComponentName(this, FooBroadcastReceiver.class), receiverState, PackageManager.DONT_KILL_APP);
      }
  
      public static class FooBroadcastReceiver extends BroadcastReceiver {
          @Override
          public void onReceive(Context context, Intent intent) {
          }
      }
  
  }
  </code></pre>
  
  <p>the receiver in the manifest :</p>
  
  <pre><code>&lt;receiver android:name="com.example.foo.FooActivity$FooBroadcastReceiver"/&gt;
  </code></pre>
  
  <p>thanks!</p>