SplashScreen crashes when device screen is turned off

时间:2018-02-15 12:30:48

标签: android

Dears I'm trying to make splash screen as fragment showing imageView the start another fragment after 5 sec

here is the activity code

public class MainActivity extends AppCompatActivity {
Fragment fragment = null;
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (savedInstanceState == null) {
        fragment = new SplashFragment();
        FragmentTransaction fragmentTransaction =
                getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container, fragment);
        fragmentTransaction.commit();

        new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                fragment = new LoginFragment();
                FragmentTransaction fragmentTransaction =
                        getSupportFragmentManager().beginTransaction();
                fragmentTransaction.replace(R.id.fragment_container, fragment);
                fragmentTransaction.commit();

            }
        }, SPLASH_TIME_OUT);


    }

} }

SplashFragment should be start first on many activity created

then LoginFragment should be started after 5 seconds

0 个答案:

没有答案