I have the following code which opens up a browser to my social profile:
ImageView iv1 = (ImageView) dialog.findViewById(R.id.imgFB);
iv1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Uri uri = Uri.parse("https://www.facebook.com/profile");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
Now when I choose the browser to open the profile, and press back, it not only closes the browser but also my app. Any way to just close the browser while keeping my app running in the background?
UPDATE:
This works fine:
ImageView iv1 = (ImageView) dialog.findViewById(R.id.imgFB);
iv1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Uri uri = Uri.parse("https://www.facebook.com/PagesByZ"); //Uri.parse("market://details?id=" + facebookpackagename);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
//intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
dialog.dismiss();
startActivity(intent);
}
});
Now I do not receive the error but when the Complete action using
window comes up and instead of picking an option I just press Back, my app just closes. Any idea how to fix it so If I press Back it goes back to my app rather than Home?
Update: The following is a rewording to help understand the issue better.
In my app I have a image link which opens the browser, but if the user has multiple browser installed it brings up the "Complete action using" window where I can choose. If I press the back button it should close it come back to my app. Instead what is happening is, if I press the back button my app just closes and I am taken back to homescreen
My MainActivity: http://pastebin.com/FVwEKLAT
My AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sikni8.tollculator"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.sikni8.tollculator.MainActivity"
android:label="@string/app_name"
android:noHistory="true"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.sikni8.tollculator.CurrentTrip"
android:label="@string/title_activity_current_trip"
android:parentActivityName="com.sikni8.tollculator.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.sikni8.tollculator.MainActivity" />
</activity>
<activity
android:name="com.sikni8.tollculator.DisplayTrip"
android:label="@string/title_activity_display_trip"
android:parentActivityName="com.sikni8.tollculator" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.sikni8.tollculator" />
</activity>
<activity
android:name="com.sikni8.tollculator.ShowHelp"
android:label="@string/app_name" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.sikni8.tollculator.MainActivity" />
</activity>
<activity
android:name="com.sikni8.tollculator.ShowSettingOptions"
android:label="@string/app_name" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.sikni8.tollculator.MainActivity" />
</activity>
</application>
</manifest>
How can I make sure that If the user changes their mind on not going to the browser and presses the back button it just goes back to my app instead of going to the home screen?
Also would fixing the above fix, in case they do goto the browser and presses the back which will close the browser and my app will come back to view?