0
我試圖重新啓動中斷的線程在onResume(我解釋onPause中的線程)。爲此,我在網上看到很多例子,但沒有什麼是有用的(可能是我的錯)。所以,請告訴我如何重新啓動中斷的線程中的onResumeAndroid:重新啓動中斷線程onResume
我的代碼:
private void runThread(){
threadService = new Thread() {
@Override
public void run() {
try {
while (!isInterrupted()) {
Thread.sleep(1000);
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.e("Thread", "thread");
if (freshMSgId != null) {
getPrevChatVolleyInThread();
}
}
});
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
threadService.start();
}
@Override
protected void onPause() {
super.onPause();
if (threadService != null) {
threadService.interrupt();
}
}
您不能重新啓動被中斷的線程。有一些很好的想法,你可以*在接受的答案在這裏做:http://stackoverflow.com/questions/1881714/how-to-start-stop-restart-a-thread-in-java – npace