tags:

views:

128

answers:

1

Hello. I have a problem and that is my SplashScreen I have. It is built as an intro and after 3 seconds it shows the main menu of the program. Anyway, if I press down Back or Home button during the time the SplashScreen shows, it closes, but the activity I have chosen to follow after the SplashScreen will still run after the three seconds.

My code: **UPDATED CODE**

    Handler ur = new Handler();
    myRun = new Runnable() {
            public void run() {     
                    mainIntent = new Intent(SplashScreen.this,MyApp.class);
                    SplashScreen.this.startActivity(mainIntent);
                    SplashScreen.this.finish(); 
                    overridePendingTransition(R.anim.fadein,
                            R.anim.fadeout);    
            }
    };
    ur.postDelayed(myRun, SPLASH_DISPLAY_TIME);
}

protected void onStop() {
    super.onStop();
    ur.removeCallbacks(myRun);
}

Even if I have an onStop() in this SplashScreen, the next activity will still run after the SPLASH_DISPLAY_TIME.

Since I changed the code I got Force Close after I pressed the Home button and the SplashScreen disappeared, also, I cannot launch my second activity.

+2  A: 

Try to do it this way:

private static final int SPLASH_DISPLAY_TIME = 3000;
Handler ur = new Handler();
Runnable yourRunnable = new Runnable() {      
        public void run() {     
                mainIntent = new Intent(SplashScreen.this,MyApp.class);
                SplashScreen.this.startActivity(mainIntent);
                SplashScreen.this.finish(); 
                overridePendingTransition(R.anim.fadein,
                        R.anim.fadeout);    
        }
};
ur.postDelayed(yourRunnable, SPLASH_DISPLAY_TIME);

Then, somewhere on onDestroy or whatever method you use to detect when your splashscreen activity get closed:

// somewhere
ur.removeCallbacks(yourRunnable);
Cristian
It works! Accepted!
Julian Assange