首页 > 解决方案 > 已完成的启动活动在启动器上重新启动

问题描述

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

}

使用 singleTop 启动模式登陆活动

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

标签: android

解决方案


试试这样:

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

推荐阅读