0
私はonResumeで中断されたスレッドを再開しようとしています(私はonPauseでスレッドを解釈しています)。このために私はオンラインで多くの例を見ましたが、何も役立たなかった(私のせいかもしれない)。だから、 Android:onResumeで中断されたスレッドを再起動
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