Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Farouk Charkas
1,957 PointsHow do I program a splash screen?
I would like to program my application to start of to display my splash screen for 5 seconds, how do I do that?
2 Answers
Jordan Peterson
5,134 PointsFirst you will need to have a image to display for your splash screen. Then make your splash screen activity your launcher activity (You can do this in the Manifest). In your SplashScreenActivity you can add this:
Thread timerThread = new Thread() {
@Override
public void run() {
try {
sleep(3000);
}
catch(InterruptedException e) {
e.printStackTrace();
}
finally {
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(intent);
}
}
};
timerThread.start();
}
@Override
protected void onPause() {
super.onPause();
finish();
}```
Jordan Peterson
5,134 PointsThis is how you can add an image for your Splash Screen: Find your xml file for your activity. (This is located in your folder at Res -> Layout) Then inside your xml file add this inside of your relative layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash_image"
android:orientation="vertical" >
</LinearLayout>
Farouk Charkas
1,957 PointsUnderstood, now could you explain your code line by line? I would greatly appreciate that.
Farouk Charkas
1,957 PointsUnderstood, now could you explain your code line by line? I would greatly appreciate that.
Farouk Charkas
1,957 PointsFarouk Charkas
1,957 PointsBut where would I add the image?
Farouk Charkas
1,957 PointsFarouk Charkas
1,957 PointsBut where would I add the image?