0

I have a simple app with two activities, a splash activity that displays an animation, then starts a singleTop landing activity(to handle opening the app through a notification) and finishes. When the app is started from the launcher, that splash activity is called again even if the app was already running. What's also weird is that this behavior never happens when I am debugging the app, only with the installed released apk

Splash activity

   <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>

Navigating to the landing activity and finishing

private void navigateToLandingScreen() {

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

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

}

Landing activity with a singleTop launchMode

   <activity
        android:launchMode="singleTop"
        android:name=".LandingActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan"/>
sam winston
  • 162
  • 1
  • 13

1 Answers1

0

Try like this:

overridePendingTransition(R.anim.splash_fadein, R.anim.splash_fadeout);
finish();
SplashScreen.finish();
  • Why, isn't calling finish from within the activity you want to finish is enough ? – sam winston Jul 11 '18 at 11:47
  • Usually finish() method be called on something that have its own life cycle (like an activity). But here you are calling it from a function that don't have any prescribed lifecycle. So 'SplashScreen.finish();' should work for you. It also worked for me. You can refer [this](https://stackoverflow.com/questions/16402844/call-finish-from-static-method) answer for more info – Karthic Srinivasan Jul 11 '18 at 13:18
  • finish is called from within SplashScreen, so I don't understand why I should call it as if it was static. It won't compile anyway – sam winston Jul 11 '18 at 21:20