can someone explain me how to make splash screen in fragment using android studio. I want to make the HomeFragment will appear after the splash. As your information, I am using navigation drawer in my apps.
Asked
Active
Viewed 1,860 times
3 Answers
0
Do not try to create splash screen in fragment. Create your splash screen as launcher activity, put some timer on it then load your main activity that extends FragmentActivity:
public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
Your MainActivity will serve as fragment container. In that activity load your HomeFragment initially.
-
I had tried your code and its work. Thank you for your help :) – Hilda Jul 06 '15 at 02:19
0
Make Splashscreen as Activity. Here is similar problem already resolved: How do I make a splash screen?

Community
- 1
- 1

Damian Kozlak
- 7,065
- 10
- 45
- 51
0
@Override
public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated( view, savedInstanceState );
Thread thread=new Thread( ) {
@Override
public void run() {
try {
sleep( 3000 );
Navigation.findNavController(view).navigate( R.id.action_splashScreen_to_mainFragment );
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
thread.start();
}

Mustafa Al-Salhi
- 113
- 1
- 6