Veljko
Veljko

Reputation: 1903

Android return from browser to app

I have option in my app to start browser and load imdb website. I'm using ActionView for this.

        Intent intent1 = new Intent(android.content.Intent.ACTION_VIEW,
                Uri.parse(website));

        try {
            activity.startActivity(intent1);
        } catch (Exception e) {
            Toast.makeText(activity, R.string.no_imdb, Toast.LENGTH_SHORT)
                    .show();
        }

The problem occurs when I tap on back button. When default browser app is launched everything is ok. When Opera Mini app is launched, when I tap on back button, it seems like my app receives two back actions, and finish my current activity.

How to prevent this?

Upvotes: 4

Views: 5927

Answers (3)

Milad jalali
Milad jalali

Reputation: 692

Also You can Use Airbnb DeepLink lib

Example

Here's an example where we register SampleActivity to pull out an ID from a deep link like example://example.com/deepLink/123. We annotated with @DeepLink and specify there will be a parameter that we'll identify with id.

@DeepLink("example://example.com/deepLink/{id}")
public class SampleActivity extends Activity {
  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    if (intent.getBooleanExtra(DeepLink.IS_DEEP_LINK, false)) {
      Bundle parameters = intent.getExtras();
      String idString = parameters.getString("id");
      // Do something with idString
    }
  }
}

Upvotes: 1

Milad jalali
Milad jalali

Reputation: 692

Please add this code to your android manifest for activity that you need return

    <activity
        android:name="YourActivityName"
        android:launchMode="singleTask">
        <intent-filter>
            <action android:name="schemas.your_package.YourActivityName" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.ALTERNATIVE" />

        </intent-filter>
    </activity>

and add this to your web page

<a href="intent:#Intent;action=schemas.your_package.YourActivityName;end">click to load app</a>

because only one app has this action name (schemas.your_package.YourActivityName) on your phone, web page directly return to app

Upvotes: 6

sdabet
sdabet

Reputation: 18670

Try starting the intent in a new task:

intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Or

intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Upvotes: 5

Related Questions