所以活动开始了,我创建了一个线程来检查何时进入下一个活动。但有时我需要这种活动来杀死自己。onPause 会这样做,但在那之后 Thread 仍然活着,并且在时间用完后它会开始一个新的活动。是否有可能杀死这个线程并停止 goToFinals 意图?
public class Questions extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String in = getIntent().getStringExtra("time");
long tmp = Long.parseLong(in);
endTime = (long) System.currentTimeMillis() + tmp;
Thread progress = new Thread(new Runnable() {
public void run() {
while(endTime > System.currentTimeMillis()) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Intent goToFinals = new Intent(Questions.this,End.class);
startActivity(goToFinals);
}
});
progress.start();
}
@Override
protected void onPause() {
super.onPause();
finish();
}
}