【发布时间】:2016-05-14 10:50:27
【问题描述】:
我正在尝试重新启动 onResume 中的中断线程(我正在解释 onPause 中的线程)。为此,我在网上看到了很多示例,但没有任何帮助(可能是我的错)。所以,请告诉我如何在 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();
}
}
【问题讨论】:
-
您无法重新启动已中断的线程。在此处接受的答案中有一些关于您可以做什么的好主意:stackoverflow.com/questions/1881714/…
标签: android multithreading onresume onpause