I have a Splash Screen activity that looks like this:

        <activity
            android:name=".activity.BoardingActivity"
            android:configChanges="layoutDirection|locale"
            android:exported="true"
            android:label="@string/app_name"
            android:noHistory="true"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

Inside the BoardingActivity, I call the MainActivity once the animation is done.

Intent intent = new Intent(this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NO_HISTORY);
        startActivity(intent);

In Samsung devices running Android 14, the startActivity function is causing the MainActivity to constantly create, destroy itself. The activities are getting created on different threads and new threads are being created even before the old ones are destroyed. The savedBundleState is always empty for the newly created activities. This is an infinite loop that keeps happening until the app crashes. It works normally in non-samsung devices running Android 14.

Any help or advice is appreciated.

I have tried changing the launch activity to a different activity but the same thing happens when I call startActivity. I have also changed the launchMode to singleTask or singleTop but neither of them worked.

2

There are 2 best solutions below

2
Ihor Bykov On

Starting from Android 12, there is a new and recommended way to implement Splash Screen now

0
Piyush On

Update: Turns out the activities kept getting destroyed because of the below code in my BaseActivity:

protected void onResume() {
        super.onResume();

        loadLocale();
    }

    private void loadLocale(){
        PreferenceHelper preferenceHelper = new PreferenceHelper(this);
        Locale locale = preferenceHelper.getLocale();
        Configuration config = getBaseContext().getResources().getConfiguration();

        if (!config.locale.equals(locale)) {
            Locale.setDefault(locale);
            config.locale = locale;
            getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
            Resources.getSystem().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());

            restartActivity();
        }
    }

For some reason, updateConfiguration was not actually updating the configuration on Samsung devices running Android 14. So the loadLocale constantly restarts the activity since it thinks the locale never matches. I tried using createConfigurationContext and Wrappers since updateConfiguration is deprecated but neither seemed to work. I have just commented out the line that restarts the activity to unblock users. I'll investigate why configuration is not getting updated later.