I have created a splash screen for my application. After 5 seconds it starts the next activity using the below code. Now my problem is, if user navigates away from current activity before 5 seconds are over, then as soon as 5 seconds are over the next activity (in my case InfoActivity) comes in front even if I am in another application or anywhere else.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.launch);
new Handler().postDelayed(new Runnable() {
public void run() {
final Intent mainIntent = new Intent(LaunchActivity.this, InfoActivity.class);
LaunchActivity.this.startActivity(mainIntent);
LaunchActivity.this.finish();
}
}, 5000);
}
This procedure worked for me.