【问题标题】:How to return back to browser after it sends Intent to start my app without exiting from my app?如何在发送 Intent 以启动我的应用程序而不退出我的应用程序后返回浏览器?
【发布时间】:2014-04-09 16:24:03
【问题描述】:

所以我在 Manifest 中声明了这么棘手的事情,以便能够从浏览器启动我的应用程序:

<activity android:name=".BrowserIntentCallBackActivity"
    android:noHistory="true" >
    <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:scheme="trickyapp" />
    </intent-filter>
</activity>

这工作正常并按预期启动我的BrowserIntentCallBackActivity。如果我的应用程序之前没有启动,那么完成 BrowserIntentCallBackActivity 会将用户返回到浏览器并且它很好。
但是,如果我的应用程序之前已启动并在后台运行,则 BrowserIntentCallBackActivity 会将用户返回到我的应用程序的 previuos 活动。但是我想将用户发送回浏览器,他/她在其中单击了非常特殊的链接,并且我的BrowserIntentCallBackActivity 是由intent 启动的。而且我不想杀死我正在运行的应用程序。
如何做到这一点?

【问题讨论】:

    标签: android android-intent android-activity


    【解决方案1】:

    尝试设置活动的启动模式:

    https://developer.android.com/guide/topics/manifest/activity-element.html#lmode

    我相信您的任务的正确模式将是“singleTask”或“singleInstance”,尽管我对这些的经验有限,因此您必须进行试验才能确定。

    【讨论】:

    • 注意,如果您有时也从内部启动 Activity,您可以尝试在 Intent 上而不是在清单中设置启动模式,因此它的行为会有所不同,具体取决于它是否来自浏览器或内部。
    • 我是这么想的(我的意思是设置活动的启动模式标志),但认为 smb 可以准确判断要使用哪些参数/标志。还有很多隐藏的行为,比如如果你使用 singleInstance 然后单击 Home(将应用程序发送到 bg)也会杀死活动,这不是一个选项。
    • 是的,这两个标志很少使用,这是有原因的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    • 2011-01-16
    • 1970-01-01
    • 2011-05-11
    • 2014-06-24
    相关资源
    最近更新 更多