android 一个Activity如何才能每次启动都进入不同的任务栈
高洛峰
高洛峰 2017-04-17 12:01:16
[Android讨论组]

我的应用中有一个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去掉,这样的话打开会在应用任务栈中,不会独立出来。
求大神帮忙,谢谢了。

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(1)
PHP中文网

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号