0
votes

I just created my first proper android app and ran into the splash screen issue. Whenever my app comes into foreground, splash screen is displayed first and then the last opened activity is shown. The resume feature looks fine but why the splash screen is always showed. In other apps, I don't see such behavior. Here is my code:

minSdkVersion 24
targetSdkVersion 26

I used android:noHistory="true" but still no changes I tried intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); but still no change

From AndroidManifesh.xml

<activity
        android:noHistory="true"
        android:label="@string/app_name"
        android:name=".activities.SplashActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:noHistory="true"
        android:configChanges="keyboardHidden"
        android:name=".activities.MainActivity" />

From SplashActivity.java

Handler handler;

@Override
public void onCreate(Bundle savedInstanceState) {
            handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent intent = new Intent(SplashActivity.this, MainActivity.class);

                    startActivity(intent);
                    finish();
                }
            }, Constant.SPLASH_SCREEN_TIMEOUT);
}

What am I missing? Any more code is required for explanation?

1
Please share you MainActivity code also, maybe some thing is wrong in yourMainActivity - PriyankVadariya
If this is happening when navigating back from RegistrationPhoneNumberActivity to SplashActivity by clicking back button, you should override onBackPressed() in RegistrationPhoneNumberActivity and then call finish() inside it. - Mohammed Farhan
@MohammedFarhan edited code - Ashutosh
This is happening on all activities. I am on a screen, press the home button on phone. Now, whether I resume the app or click the icon to open it, I always see the splash screen. I can see app is running in the background. - Ashutosh
this is happening because you must be calling finish() in onBackPressed in your activities , do call finish() in activities - Quick learner

1 Answers

2
votes

Remove this android:noHistory="true" from all the activities.

A value of "true" means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it