0

I am using the single-activity approach. I need to display a splash screen. For this I am using the following code:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_bg</item>
    </style>

And in AndroidManifest:

 <activity
            android:theme="@style/SplashTheme"
            android:name=".presentation.app.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

Everything works well, but I would like to slightly increase the duration of the splash screen, is it possible to do this?

testivanivan
  • 967
  • 13
  • 36

1 Answers1

0

You define a handler in the Activity you want to delay like this:

public class SplashActivity extends AppCompatActivity {


    private static int SPLASH_TIME_OUT = 1000;

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

            new Handler().postDelayed(() -> {
            Intent homeIntent = new Intent(SplashActivity.this, NextActivity.class);
            startActivity(homeIntent);
            finish();

        },SPLASH_TIME_OUT);
    }

1 sec = 1000 like in this example. Cheers :)

Don't forget to add your Splashactivity into your AndroidManifest.xml:

<activity android:name="com.example.Dex7raCryptoAlert.Main.SplashActivity"
Ole Pannier
  • 3,208
  • 9
  • 22
  • 33
  • Thanks for your reply. But I would not like to create a separate activity for the splash screen. I thought maybe there is some way to solve my problem using the approach I gave – testivanivan May 22 '21 at 20:52
  • Let me see what I find, but I suggest to do a activity for the Splash Screen. It can be more customized than your option. – Ole Pannier May 22 '21 at 20:55
  • Mine and the second answer of the following post is the way to go: https://stackoverflow.com/questions/5486789/how-do-i-make-a-splash-screen Good luck with that. Your question should answered by now :) – Ole Pannier May 22 '21 at 21:01
  • Is there a way to decrease duration instead? – Klem Lloyd Mwenya Oct 03 '22 at 09:16
  • Yes with lowering the time: private static int SPLASH_TIME_OUT = 1000; – Ole Pannier Oct 03 '22 at 11:29