更新活动的意图

时间:2012-05-03 16:19:33

标签: android android-intent android-manifest

我在活动中从意图中获取URI时遇到问题。

这是清单中的代码:

<activity android:name=".ui.Library"
          android:label="@string/app_name"
          android:launchMode="singleTask" >
    <intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:host="*"
                android:pathPattern=".*\\.xyzandroid"
                android:scheme="http" />
            <data
                android:host="*"
                android:pathPattern=".*\\.xyzandroid"
                android:scheme="https" />
            <data
                android:host="*"
                android:pathPattern=".*\\.xyzandroid"
                android:scheme="content" />
            <data
                android:host="*"
                android:pathPattern=".*\\.xyzandroid"
                android:scheme="file" />
        </intent-filter>
    </activity>

问题在于,我的主要活动只是在我的活动第一次启动时的意图:这意味着,例如,如果用结尾.xyzandroid点击链接,我的活动开始我获取URI。但是我的活动是从启动器开始的,如果有人点击浏览器中的链接,我就无法获取URI。

如何解决此问题?有任何想法吗?谢谢!

1 个答案:

答案 0 :(得分:1)

Selvin是对的,你只需要覆盖。

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    // getIntent() should always return the most recent
    setIntent(intent);
}