我想知道如果我要离开Activity
. 查看下面的示例,我可以看到Runnable
in a separateThread
正在执行,即使我在另一个Activity
. 但是什么时候会被杀死呢?
public class MyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
runTask();
startActivity(new Intent(this, SecondActivity.class));
}
private void runTask() {
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
Log.i("Dev", "here I am");
SystemClock.sleep(1000);
}
}
}).start();
}
}