title: Calling startActivity() from outside of an activity context requires the FLAG_ACTIVITY_NEW_TASK
body: <p>I am trying to start an activity inside a service class. I have a following code:</p>
  
  <pre><code>public class SendLinkService extends Service {
  
  @Override
  public IBinder onBind(Intent intent) {
      // TODO Auto-generated method stub
      return null;
  }
  
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
      Bundle bundle = intent.getExtras();
      Intent shareIntent = new Intent(Intent.ACTION_SEND);
      shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      shareIntent.setType("text/plain");
      shareIntent.putExtra(Intent.EXTRA_TEXT, bundle.getString("URL"));
      getApplicationContext().startActivity(Intent.createChooser(shareIntent, "Share via"));
      return super.onStartCommand(intent, flags, startId);
  }
  }
  </code></pre>
  
  <p>It gives exception on following line of onStartCommand() :</p>
  
  <pre><code>getApplicationContext().startActivity(Intent.createChooser(shareIntent, "Share via"));
  </code></pre>