4

我可以在我的应用程序中选择启动浏览器并加载 imdb 网站。我为此使用 ActionView。

        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();
        }

当我点击后退按钮时会出现问题。启动默认浏览器应用程序时,一切正常。当 Opera Mini 应用程序启动时,当我点击后退按钮时,我的应用程序似乎收到了两个后退操作,并完成了我当前的活动。

如何防止这种情况?

4

3 回答 3

5

尝试在新任务中启动意图:

intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

或者

intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
于 2012-11-22T11:54:34.470 回答
4

请将此代码添加到您需要返回的活动的 android 清单中

    <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>

并将其添加到您的网页

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

因为你手机上只有一个app有这个动作名称(schemas.your_package.YourActivityName),网页直接返回app

于 2018-08-26T05:07:10.193 回答
1

您也可以使用Airbnb DeepLink lib

例子

这是一个示例,我们注册 SampleActivity 以从例如 example://example.com/deepLink/123 之类的深层链接中提取 ID。我们用@DeepLink 注释并指定将有一个我们将用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
    }
  }
}
于 2020-10-01T07:10:46.813 回答