<bdo id='pi5Y8'></bdo><ul id='pi5Y8'></ul>
    1. <tfoot id='pi5Y8'></tfoot>
    2. <legend id='pi5Y8'><style id='pi5Y8'><dir id='pi5Y8'><q id='pi5Y8'></q></dir></style></legend>

      <small id='pi5Y8'></small><noframes id='pi5Y8'>

      <i id='pi5Y8'><tr id='pi5Y8'><dt id='pi5Y8'><q id='pi5Y8'><span id='pi5Y8'><b id='pi5Y8'><form id='pi5Y8'><ins id='pi5Y8'></ins><ul id='pi5Y8'></ul><sub id='pi5Y8'></sub></form><legend id='pi5Y8'></legend><bdo id='pi5Y8'><pre id='pi5Y8'><center id='pi5Y8'></center></pre></bdo></b><th id='pi5Y8'></th></span></q></dt></tr></i><div id='pi5Y8'><tfoot id='pi5Y8'></tfoot><dl id='pi5Y8'><fieldset id='pi5Y8'></fieldset></dl></div>

    3. 如何在使用不同的 Intent 启动 Activity 时防止其出现多个实例

      How to prevent multiple instances of an Activity when it is launched with different Intents(如何在使用不同的 Intent 启动 Activity 时防止其出现多个实例)

    4. <tfoot id='x1Dep'></tfoot>

      <i id='x1Dep'><tr id='x1Dep'><dt id='x1Dep'><q id='x1Dep'><span id='x1Dep'><b id='x1Dep'><form id='x1Dep'><ins id='x1Dep'></ins><ul id='x1Dep'></ul><sub id='x1Dep'></sub></form><legend id='x1Dep'></legend><bdo id='x1Dep'><pre id='x1Dep'><center id='x1Dep'></center></pre></bdo></b><th id='x1Dep'></th></span></q></dt></tr></i><div id='x1Dep'><tfoot id='x1Dep'></tfoot><dl id='x1Dep'><fieldset id='x1Dep'></fieldset></dl></div>
      • <bdo id='x1Dep'></bdo><ul id='x1Dep'></ul>

            <small id='x1Dep'></small><noframes id='x1Dep'>

                <tbody id='x1Dep'></tbody>
                <legend id='x1Dep'><style id='x1Dep'><dir id='x1Dep'><q id='x1Dep'></q></dir></style></legend>
                本文介绍了如何在使用不同的 Intent 启动 Activity 时防止其出现多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在使用 Google Play 商店应用(以前称为 Android Market)上的打开" 按钮启动应用程序时遇到了一个错误.似乎从 Play 商店启动它使用的 Intent 与从手机的应用程序图标菜单启动它不同.这会导致启动同一个 Activity 的多个副本,这些副本相互冲突.

                I've come across a bug in my application when it is launched using the "Open" button on the Google Play Store app (previously called Android Market). It seems that launching it from the Play Store uses a different Intent than launching it from the phone's application menu of icons. This is leading to multiple copies of the same Activity being launched, which are conflicting with each other.

                例如,如果我的应用由活动 A-B-C 组成,那么此问题可能会导致 A-B-C-A 堆栈.

                For example, if my app consists of the Activities A-B-C, then this issue can lead to a stack of A-B-C-A.

                我尝试在所有活动上使用 android:launchMode="singleTask" 来解决此问题,但是每当我点击 HOME 时,它都会产生将 Activity 堆栈清除为根目录的不良副作用按钮.

                I tried using android:launchMode="singleTask" on all the Activities to fix this problem, but it has the unwanted side-effect of clearing the Activity stack to root, whenever I hit the HOME button.

                预期的行为是: A-B-C -> HOME -> 当应用程序恢复时,我需要: A-B-C -> HOME -> A-B-C

                The expected behavior is: A-B-C -> HOME -> And when the app is restored, I need: A-B-C -> HOME -> A-B-C

                有没有一种好方法可以防止启动多个相同类型的 Activity,而无需在使用 HOME 按钮时重置为根 Activity?

                Is there a good way to prevent launching multiple Activities of the same type, without resetting to the root activity when using the HOME button?

                推荐答案

                将此添加到 onCreate 中,您应该可以开始了:

                Add this to onCreate and you should be good to go:

                // Possible work around for market launches. See https://issuetracker.google.com/issues/36907463
                // for more details. Essentially, the market launches the main activity on top of other activities.
                // we never want this to happen. Instead, we check if we are the root and if not, we finish.
                if (!isTaskRoot()) {
                    final Intent intent = getIntent();
                    if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(intent.getAction())) {
                        Log.w(LOG_TAG, "Main Activity is not the root.  Finishing Main Activity instead of launching.");
                        finish();
                        return;       
                    }
                }
                

                这篇关于如何在使用不同的 Intent 启动 Activity 时防止其出现多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Android - Is it possible to get install referrer programmatically(Android - 是否有可能以编程方式安装引荐来源网址)
                How to sign an APK with more than one certificate?(如何使用多个证书签署 APK?)
                versionCode vs versionName in Android Manifest(Android Manifest 中的 versionCode 与 versionName)
                What does this Google Play APK publish error message mean?(这个 Google Play APK 发布错误消息是什么意思?)
                Lost my keystore for uploaded app on android market(丢失了我在 android 市场上上传的应用程序的密钥库)
                App on Google Play always shows quot;Updatequot; instead of open(Google Play 上的应用程序总是显示“更新;而不是打开)

                  <legend id='lZbCn'><style id='lZbCn'><dir id='lZbCn'><q id='lZbCn'></q></dir></style></legend>
                1. <i id='lZbCn'><tr id='lZbCn'><dt id='lZbCn'><q id='lZbCn'><span id='lZbCn'><b id='lZbCn'><form id='lZbCn'><ins id='lZbCn'></ins><ul id='lZbCn'></ul><sub id='lZbCn'></sub></form><legend id='lZbCn'></legend><bdo id='lZbCn'><pre id='lZbCn'><center id='lZbCn'></center></pre></bdo></b><th id='lZbCn'></th></span></q></dt></tr></i><div id='lZbCn'><tfoot id='lZbCn'></tfoot><dl id='lZbCn'><fieldset id='lZbCn'></fieldset></dl></div>

                    <tbody id='lZbCn'></tbody>
                    1. <tfoot id='lZbCn'></tfoot>

                      • <bdo id='lZbCn'></bdo><ul id='lZbCn'></ul>

                        • <small id='lZbCn'></small><noframes id='lZbCn'>