I have an splash activity which should appear for a brief period of time before the home activity launches. This is my code:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class SplashActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
/****** Create Thread that will sleep for 5 seconds *************/
Thread background = new Thread() {
public void run() {
try {
// Thread will sleep for 2.5 seconds
sleep(2500);
//Remove activity
finish();
// After 2.5 seconds redirect to another intent
Intent i=new Intent(getBaseContext(),HomeActivity.class);
startActivity(i);
} catch (Exception e) {
}
}
};
// start thread
background.start();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
Currently this works perfectly except for the fact that when I go back to home screen (without explicitly killing the app), and resume it, it shows the splash screen again. How do I ensure the splash screen appears only when I launch the app afresh?