【问题标题】:a finished splash activity restarts on launcher已完成的启动活动在启动器上重新启动
【发布时间】:2018-07-11 11:30:18
【问题描述】:

我有一个简单的应用程序,其中包含两个活动,一个显示动画的启动活动,然后启动一个单顶登陆活动(通过通知处理打开应用程序)并完成。当应用程序从启动器启动时,即使应用程序已经在运行,也会再次调用该启动活动。同样奇怪的是,当我调试应用程序时,这种行为永远不会发生,只有安装了已发布的 apk

飞溅活动

   <activity
        android:name=".SplashScreen"
        android:exported="true"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:stateNotNeeded="true"
        android:theme="@android:style/Animation">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

导航到着陆活动并完成

private void navigateToLandingScreen() {

    Intent intent = new Intent(SplashScreen.this, LandingActivity.class);
    startActivity(intent);

    overridePendingTransition(R.anim.splash_fadein, R.anim.splash_fadeout);
    finish();

}

单顶启动模式的着陆活动

   <activity
        android:launchMode="singleTop"
        android:name=".LandingActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan"/>

【问题讨论】:

    标签: android


    【解决方案1】:

    试试这样:

    overridePendingTransition(R.anim.splash_fadein, R.anim.splash_fadeout);
    finish();
    SplashScreen.finish();
    

    【讨论】:

    • 为什么,在您想要完成的活动中调用完成还不够吗?
    • 通常在有自己生命周期的东西(如活动)上调用 finish() 方法。但是在这里,您是从没有任何规定生命周期的函数中调用它的。所以'SplashScreen.finish();'应该为你工作。它也对我有用。您可以参考this答案了解更多信息
    • finish 是从 SplashScreen 中调用的,所以我不明白为什么我应该将它称为静态的。它无论如何都不会编译
    猜你喜欢
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-18
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    相关资源
    最近更新 更多