There is a Button that start an activity every 30 second by a thread. My problem is when I start the activity I cannot cancel or pause it and it runs periodically when I go back to the previous page or even home screen and show the Intent. ans also when I come back and change some setting like loop duration and press the Button, the new thread is added to previous one and both run with their loop time.
I tried to use finish() in onPause() or interrupt but I could not solve the problem!
Thread timer = new Thread(){
public void run(){
    try {
            webWiew.loadUrl(xxxxxxx);
        sleep(30000);       
    } catch (InterruptedException e) {
        e.printStackTrace();
    }finally{
        Intent runNewIntent =new Intent("The Intent Name");
        startActivity(runNewIntent);
            }
        }
    };
    timer.start();
} 
@Override
protected void onPause() {
    super.onPause();
    finish();
}
I was wondering if you tell me how can I stop or kill the thread when I leave the activity by pressing a keyboard or return button or go out of the program.