安装失败后​​的第一次启动时恢复活动栈 [英] Fail to resume the activity stack during 1st launching after installation

查看:105
本文介绍了安装失败后​​的第一次启动时恢复活动栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序有一个防溅活动(发射器主要活动)等多项活动。在大多数情况下,当用户切换到应用的背景和从发射恢复它,旧的活动堆重新开始,在该堆顶部活性示如预期。

Our application has a splash activity (main activity for launcher) and many other activities. In most cases, when the user switches the application into background and resumes it from launcher, the old activity stack is resumed and top activity in that stack is shown as expected.

然而,当APK刚刚安装了电话,或同一应用程序的安装新的APK(更高版本)时,它的行为很奇怪。当应用程序被切换到背景和从发射器恢复的,previous活性堆栈不恢复,飞溅活动总是显示。如果我们继续从最近的应用程序列表中的应用程序,活动堆栈恢复正常。只有从最近的应用程序列表查杀任务后,一切又恢复正常。在previous活动栈将永远是正确的恢复,直到它被替换为另一个APK安装了。

However, when the apk is just installed on the phone, or a new apk (with higher version) of the same application is installed, its behavior is strange. When the application is switched to background and resumed from launcher, the previous activity stack is not resumed and the splash activity is always shown. If we resume the application from recent applications list, the activity stack is resumed as expected. Only after killing the task from recent applications list, everything becomes normal again. The previous activity stack will always be resumed correctly until it is replaced by another apk installation again.

我的Andr​​oid版本是4.1.2,我使用它的缺省启动程序。

My Android version is 4.1.2 and I am using its default launcher.

以下是飞溅活动的配置。

Following is configuration of the splash activity.

<activity android:name=".welcome.activity.SplashActivity" android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

谁的奇怪行为的任何想法?在此先感谢!

Who has any idea about the strange behavior? Thanks in advance!

推荐答案

最后,我发现这是Android系统的问题。它已经在<一个讨论href="http://stackoverflow.com/questions/1845460/activity-history-stack-wrong-upon-first-install-on-device">Activity历史堆栈在第一次错误安装在设备上?。

Finally I have found this is an issue of Android system. It has already been discussed in Activity history stack wrong upon first install on device?.

我已经通过在 HTTPS指出一个解决方法: //$c$c.google.com/p/android/issues/detail?id=2373#c40 和它运作良好,即添加以下code在SplashActivity.onCreate():

I have adopted a workaround stated in https://code.google.com/p/android/issues/detail?id=2373#c40 and it works well, i.e. adding the following code in SplashActivity.onCreate():

    if (!isTaskRoot()) {
        Intent intent = getIntent();
        String action = intent.getAction();
        if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action != null && action.equals(Intent.ACTION_MAIN)) {
            finish();
            return;
        }
    }

这篇关于安装失败后​​的第一次启动时恢复活动栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆