I have made a story line which automatically loads the second activity, when I press my skip button it jumps to the right activity. Then, suddenly, it goes back to the story line and continues the story line activity up to the end of story. Here is my code, kindly modify or check it. Thanks a lot.
public class pgone extends Activity {
private long splashDelay = 4000;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pgone);
TimerTask task = new TimerTask()
{
public void run() {
Intent mainIntent = new Intent().setClass(pgone.this, pgtwo.class);
startActivity(mainIntent);
finish();
}
};
Timer timer = new Timer();
timer.schedule(task, splashDelay);
Button skipButton = (Button)findViewById(R.id.skip);
skipButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent skipIntent = new Intent(pgone.this,gamelevel.class);
startActivity(skipIntent);
finish();
}
});
}
@override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK)
{
moveTaskToBack(true);
finish();
return true; // return
}
return false;
}
}
You havent stop your timer after calling a new Activity. TimerTask is background process so its keep running in the background, you have to cancel it.
Try to use this method in your skip button listener.