title: Calling an Activity from a Service
body: <p>I have a service class for an alarm service containing the service methods. These methods are called when the alarm service is activated. What I want to do is to call an intent to another class in one of these methods that are called in the service class (when the alarm goes off). All it does is just flag up errors when calling the intent. This only happens in the methods that are called when the alarm service is activated (methods in service class). Is this because the class <code>extends Service</code> and not <code>extends Activity</code>? I'm not sure, any ides?</p>
  
  <p>(Below is my service class, when the intent to another activity is called in the <code>onStart</code> method the app force closes.)</p>
  
  <pre><code>public class MyAlarmService extends Service {
      @Override
      public void onCreate() {
          // TODO Auto-generated method stub
          Toast.makeText(this, "MyAlarmService.onCreate()", Toast.LENGTH_LONG).show();
      }
  
      @Override
      public IBinder onBind(Intent intent) {
          // TODO Auto-generated method stub
          Toast.makeText(this, "MyAlarmService.onBind()", Toast.LENGTH_LONG).show();
          return null;
      }
  
      @Override
      public void onDestroy() {
          // TODO Auto-generated method stub
          super.onDestroy();
          Toast.makeText(this, "MyAlarmService.onDestroy()", Toast.LENGTH_LONG).show();
      }
  
      @Override
      public void onStart(Intent intent, int startId) {
          // TODO Auto-generated method stub
          super.onStart(intent, startId);
  
          Toast.makeText(this, "MyAlarmService.onStart()", Toast.LENGTH_LONG).show();
  
          //////////////////////////////////////////////////////////////////////////////////
  
          Intent i = new Intent("com.exercise.AndroidAlarmService.HELLO"); 
          startActivity(i); 
  
          The intent that is send to open another class, an activity.
          **
  
          /////////////////////////////////////////////////////////////////////////////////
      }
  
      @Override
      public boolean onUnbind(Intent intent) {
          // TODO Auto-generated method stub
          Toast.makeText(this, "MyAlarmService.onUnbind()", Toast.LENGTH_LONG).show();
          return super.onUnbind(intent);
      }
  }
  </code></pre>
  
  <p>One of these errors on the LogCat is:</p>
  
  <blockquote>
    <p>06-24 01:11:36.857: E/AndroidRuntime(10805): java.lang.RuntimeException: Unable to     start service com.exercise.AndroidAlarmService.MyAlarmService@412f23f8 with Intent { flg=0x4 cmp=com.exercise.AndroidAlarmService/.MyAlarmService (has extras) }: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?</p>
  </blockquote>