title: redirecting to Android app from browser
body: <p>I am working on a Android app at present that request information from a server via an HTML request and gets a params string in return. This happens during the startup process in order to configure the app the first time it is run.</p>
  
  <p>To send the request to the server I call the following from the OnCreate method of the main activity of my app:</p>
  
  <pre><code>String URL = "http://myserver.mydomain.com/users/start";            
  Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL));
  startActivity(browserIntent);
  </code></pre>
  
  <p>The server, a rails app, gets the required parameter values and redirects back to the app with the following statement:</p>
  
  <pre><code>redirect_to "http://myappname.mydomain.com/?#{mobile_params.to_query}"
  </code></pre>
  
  <p>I have created an intent filter in my AndroidManifest.xml for the activity that handles the parameters that come back from the server. The intent filter looks like:</p>
  
  <pre><code>    &lt;activity
          android:name=".StartFromUriActivity"
          android:launchMode="singleTop"
          android:noHistory="true"
          android:screenOrientation="behind"
          android:theme="@style/NoTitle" 
          android:exported="true" &gt;
          &lt;intent-filter&gt;
              &lt;data android:scheme="http" android:host="myappname.mydomain.com" /&gt;
              &lt;action android:name="android.intent.action.VIEW" /&gt;
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;
               &lt;category android:name="android.intent.category.BROWSABLE" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  </code></pre>
  
  <p>Finally, the first few lines of my StartFromUriActivity.java look like this:</p>
  
  <pre><code>public class StartFromUriActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          Uri URIdata = getIntent().getData();
          if(URIdata != null) {
              parameter1value = URIdata.getQueryParameter("param1");
          }
      finish();
      }
  }
  </code></pre>
  
  <p>All of this actually works fine, with one exception. The app opens a browser, sends the URI to the server, which redirects back to the app with the desired parameter values, the intent filter directs to the activity and the parameters are read correctly. The only problem is that the browser window is left in the foreground and I have to manually close it. I have tried everything I can think of to get my app to come to the foreground and for the browser to close or go to the background without success. What am I missing that would result in my app correctly being brought to the foreground?</p>