From an activity,I want to switch to another activity either by pressing a button or by waiting for some time (For example - 5 seconds). In the code below,if the user pressed the button within less than the specified timing (e.g: 5 seconds), he will be directed to a new activity. In case the user waited (5 seconds) without pressing any thing, the new activity will also be switched to.
The problem is, if the user pressed the button - before 5 seconds- to switch to the new activity, actually he will get what he wants, BUT after (5 seconds) the same activity will be launched again. How to invalidate the timer in case of the user chose to switch to the new activity by pressing the button.
Java Code:
introButton = (Button) findViewById(R.id.introButtonID);
introButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent00 = new Intent(Intro.this, MPL.class);
startActivity(intent00);
finish();
}
});
...
...
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Intent intent01 = new Intent(Intro.this, MPL.class);
startActivity(intent01);
finish();
}
}, SPLASH_TIME_OUT);
}