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.
To send the request to the server I call the following from the OnCreate method of the main activity of my app:
String URL = "http://myserver.mydomain.com/users/start";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL));
startActivity(browserIntent);
The server, a rails app, gets the required parameter values and redirects back to the app with the following statement:
redirect_to "http://myappname.mydomain.com/?#{mobile_params.to_query}"
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:
<activity
android:name=".StartFromUriActivity"
android:launchMode="singleTop"
android:noHistory="true"
android:screenOrientation="behind"
android:theme="@style/NoTitle"
android:exported="true" >
<intent-filter>
<data android:scheme="http" android:host="myappname.mydomain.com" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
Finally, the first few lines of my StartFromUriActivity.java look like this:
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();
}
}
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?