title: startService() from the service class itself
body: <p>I try to start an android service from the service's class.
  The reason to do this is to achieve some platform independence.</p>
  
  <p>Doing this I get a NullPointerException at android.content.ContextWrapper.startService(ContextWrapper.java:326). The platform target is 2.1-update1, any suggestions? </p>
  
  <p>See the code below (I left the imports out to save some space)</p>
  
  <pre><code>/* GUI: HelloAndroid.java */
  package com.example.helloandroid;
  
  public class HelloAndroid extends Activity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          // that works!
          startService(new Intent("com.example.helloandroid.UnusualService"));
  
          // stop the service works of course, too
          stopService(new Intent("com.example.helloandroid.UnusualService"));
  
          // unusual start does not work:
          UnusualService myService = new UnusualService();
          myService.startService();
      }
  }
  
  /* Service: UnusualService.java */
  package com.example.helloandroid;
  
  public class UnusualService extends Service {    
      @Override
      public void onCreate() {
          Toast.makeText(this, R.string.service_started, Toast.LENGTH_SHORT).show();
      }
  
      @Override
      public void onDestroy() {
          Toast.makeText(this, R.string.service_stopped, Toast.LENGTH_SHORT).show();
      }
  
      @Override
      public IBinder onBind(Intent intent) {
          return null; // make something here when the rest works 
      }
  
      public void startService() {
          // folowing line will cause the NullPointerException
          startService(new Intent("com.example.helloandroid.UnusualService"));
      }
  
      public void stopService() {
          stopSelf();
      }
  }
  </code></pre>