title: Android Service to show toast
body: <p>This code is supposed to use a service to show a toast message.  There are no errors, but it doesn't show the toast.</p>
  
  <p>main activity</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Intent i= new Intent(this, BackgroundMusic.class);
      this.startService(i); 
  
  }
  
  
  
  }
  </code></pre>
  
  <p>service (its called Background Music but for now it is supposed to show a toast message)</p>
  
  <pre><code>public class BackgroundMusic extends IntentService {
  
   public BackgroundMusic() {
        super("BackgroundMusic");
    }
  
  
  
   @Override
    protected void onHandleIntent(Intent intent) {
        // Normally we would do some work here, like download a file.
        // For our sample, we just sleep for 5 seconds.
       Context context = getApplicationContext();
       CharSequence text = "Hello toast!";
       int duration = Toast.LENGTH_SHORT;
  
       Toast toast = Toast.makeText(context, text, duration);
       toast.show();
   }
  
  
  
  }
  </code></pre>
  
  <p>manifest</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.starwars"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="18" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:debuggable="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
       &lt;service android:name=".BackgroundMusic" /&gt;
      &lt;activity
          android:name="com.example.starwars.MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity android:label="@string/app_name" android:name="BackgroundMusic"/&gt;
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>