I used some thread objects in my Android activity. But these threads do not stop itself when Activity on destroy. My code for thread-stopping as following:
try this way:
volatile boolean stop = false;
public void run() {
while ( !stop ) {
log.v("Thread", "Thread running..." );
try {
Thread.sleep( 1000 );
} catch ( InterruptedException e ) {
log.v("Thread","Thread interrupted..." );
}
}
}
@Override
public void onDestroy() {
stop = true;
super.onDestroy();
}
and
@Override
public void onDestroy() {
thread.interrupt();
super.onDestroy();
}