title: Notification service put extra on notification click, how?
body: <p>Well I have a service that runs with a notification, I want to put an extra with the new intent opened when the user clicks the notification, so when <code>MainActivity</code> opens I can get the extra. I have tried with different ways, but I just don't find how to get it to work.</p>
  
  <p>Here's what I have tried:</p>
  
  <p>This is MyService</p>
  
  <pre><code>Intent intent = new Intent(MyService.this, MainActivity.class);
                      intent.putExtra("EXTRA", StringTEST);
                      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                      PendingIntent contentIntent = PendingIntent
                          .getActivity(getApplicationContext(),
                                       0, intent, 0);
  </code></pre>
  
  <p>this opens the activity fine, but I can't get the extra?? This is how I have tried to get it:</p>
  
  <p>MainActivity</p>
  
  <pre><code>@Override
  public void onNewIntent(Intent intent){
      Bundle extras = intent.getExtras();
      if(extras != null){
          String name = extras.getString("EXTRA");
          System.out.println(name);
      }
  }
  
  @Override
  protected void onResume() {
      Bundle extras = getIntent().getExtras();
      System.out.println(extras+"");
      if (extras != null) {
          try {
              onNewIntent(getIntent());
              Intent i = getIntent();
              String name = i.getStringExtra("EXTRA");
              System.out.println(name);
              currentDir = new File(name);
  
              changeFiles();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
      super.onResume();
  }
  </code></pre>
  
  <p>Those are the two ways I have tried, but I still get null... What am I doing wrong?</p>
  
  <p>Thanks</p>