title: android handle activity launching
body: <p>I have the following situation:
  when I launch my app the following scenario takes place:</p>
  
  <ul>
  <li>I start the activity <code>StartActivity</code> </li>
  <li>If I never did a login (I know it based on some shared preference)  launch <code>LoginActivity</code> and show a login layout (username and password)</li>
  <li>If I already did a login I start <code>LoginActivity</code> anyway, but I use (crypted) data saved on shared preferences without asking again credentials to the user.</li>
  <li>When the login succeed I launch the activity <code>StartActivity</code></li>
  </ul>
  
  <p>Now in my manifest file I have the following IntentFilter for <code>MainActivity</code>:</p>
  
  <pre><code>&lt;intent-filter android:label="Conio" &gt;
      &lt;action android:name="android.intent.action.VIEW" /&gt;
      &lt;data android:scheme="myprotocol" /&gt;
      &lt;category android:name="android.intent.category.DEFAULT" /&gt;
      &lt;category android:name="android.intent.category.BROWSABLE" /&gt;
  &lt;/intent-filter&gt;
  </code></pre>
  
  <p>And everything works well with a big "BUT":
  everything works only when my app is already opened: my app is brought to front, the onCreate method is called and with getIntent.getData() I can access the URI which started my app.</p>
  
  <p><strong>THE BIG PROBLEM:</strong></p>
  
  <p>WHAT I NEED IS :</p>
  
  <ul>
  <li>When my app is not already started everything should begin from <code>StartActivity</code> as per previous explanation
  
  <ul>
  <li>When my app is running the behaviour must be the current one</li>
  </ul></li>
  </ul>
  
  <p>To accomplish this I made the following attempt:
  I applied that IntentFilter to a new <code>Activity</code> , in this Activity's onCreate method I put the following code</p>
  
  <pre><code>Intent intent = getPackageManager().getLaunchIntentForPackage("my.package.name");
  if (intent != null) {
      intent.setData(intent.getData());
      intent.putExtra("test", "test");
      startActivity(intent);
      finish();
  }
  </code></pre>
  
  <p>but what happens here is that when app is not running the app correctly starts from StartActivity, but if if the app is already running, MainActivity is brought to front but I can't access the intent extras, in fact this code do not works</p>
  
  <pre><code>@Override
  protected void onResume() {
      super.onResume();
  //this code returns null
      String test=getIntent.getStringExtra("test");
  }
  </code></pre>
  
  <p>how can I make all this to work?</p>