Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 907
Veljko Avatar asked Dec 27 '22 14:12

Veljko


2 Answers

Try starting the intent in a new task:

intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Or

intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
like image 159
sdabet Avatar answered Jan 14 '23 08:01

sdabet


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

like image 41
Milad jalali Avatar answered Jan 14 '23 10:01

Milad jalali