首页 > android 一个Activity如何才能每次启动都进入不同的任务栈

android 一个Activity如何才能每次启动都进入不同的任务栈

我的应用中有一个Activity,是从桌面快捷方式启动的,我的intent是这么设置的:

 Intent addWidgetIntent = new Intent(ACTION_INSTALL_SHORTCUT);
    //        不允许重复添加到桌面
//      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    addWidgetIntent.putExtra("duplicate", false);
    addWidgetIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mineApp.getName());
    addWidgetIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);

    Intent intentLauncher = new Intent(mActivity, WebViewActivity.class);
      intentLauncher.putExtra(WebViewActivity.EXTRAS_WEB_APP_ICON_URL, mineApp.getIcon_url());
      intentLauncher.putExtra(WebViewActivity.EXTRAS_WEB_APP_URL, mineApp.getUrl());
      intentLauncher.putExtra(WebViewActivity.EXTRAS_WEB_APP_NAME, mineApp.getName());
      addWidgetIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intentLauncher);

    mActivity.sendBroadcast(addWidgetIntent);

这段代码是吧一个webapp的信息保存到intent中,然后在桌面建立快捷方式。
我的webViewActivity是这么配置的:

 <activity
            android:name=".activity.WebViewActivity"
            android:launchMode="singleInstance"
            android:configChanges="orientation|screenSize"
            android:taskAffinity="com.test.webView"
            android:alwaysRetainTaskState = "true"
            android:allowTaskReparenting="true"
            android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen">
            <intent-filter>
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
            </intent-filter>
        </activity>

现在的问题是我从桌面快捷方式启动这个Activity时,不同的webapp都是启动在同一个我定义的com.test.webview任务栈中,我需要打开不同的webapp快捷方式会进入不同的任务栈,即每个用WebViewActivity打开的webApp都进入不同的任务栈。
尝试过把taskAffinity去掉,这样的话打开会在应用任务栈中,不会独立出来。
求大神帮忙,谢谢了。


android:launchMode="singleInstance"导致了再整个application中有且仅有一个activity,所以你每次打开都是一样的
少年,要仔细阅读下面的内容哦:http://developer.android.com/guide/topics/manifest/activity-element.html

【热门文章】
【热门文章】