title: How to run startActivity from outside of the main activity
body: <p>I have a <code>MainActivity</code> class which has a <code>NotificationsListener</code> (seperate class). When a notification appears, it calls my <code>gethtml</code> class. They both extend <code>Activity</code> but the <code>startActivity</code> in my <code>gethtml</code> class doesn't work... (If I copy and test this code in my <code>MainActivity</code>, it works fine)... Anyone have an idea why it isn't working? </p>
  
  <p>This is the main class:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      IntentFilter filter = new IntentFilter();
      filter.addAction("com.kpbird.nlsexample.NOTIFICATION_LISTENER_EXAMPLE");
      startService(new Intent(MainActivity.this, NLService.class));
      Intent intent=new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
      startActivity(intent);        
  
      }
  
  @Override
  protected void onDestroy() {
      super.onDestroy();
  
  }
  }
  </code></pre>
  
  <p>This is the notification listener:</p>
  
  <pre><code>public class NLService extends NotificationListenerService {
  
  @Override
  public void onCreate() {
      super.onCreate();
      IntentFilter filter = new IntentFilter();
      filter.addAction("com.kpbird.nlsexample.NOTIFICATION_LISTENER_SERVICE_EXAMPLE");
  }
  
  @Override
  public void onDestroy() {
      super.onDestroy();
  }
  
  @Override
  public void onNotificationPosted(StatusBarNotification sbn) {   
      new Thread(new Runnable() {             
              public void run(){
              Looper.prepare();
              int cangethtml = 1;
                  try{
                      if(cangethtml==1){
                          cangethtml = 0; //only runs once
                          new html();
                      }
                  }finally{Looper.loop();}  
              }; 
          }).start();    
      }
  
  @Override
  public void onNotificationRemoved(StatusBarNotification sbn) {}
  }
  </code></pre>
  
  <p>This is the final class which doesn't open the website through the <code>startActivity</code>:</p>
  
  <pre><code>public class html extends Activity{
  public html()  {
      try {
                  Intent i2 = new Intent("android.intent.action.MAIN");
                  i2.setComponent(ComponentName.unflattenFromString("com.android.chrome/com.android.chrome.Main"));
                  i2.addCategory("android.intent.category.LAUNCHER");
                  i2.setData(Uri.parse("https://wwww.google.com"));
                  startActivity(i2);
  
      }   finally{}
  }
  }
  </code></pre>