我试图在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();
}
}
@npace谢谢你,我从你的评论中得到了这个想法。我像一样在onResume中重新启动了中断的线程
@Override
protected void onResume() {
super.onResume();
runThread();
}