0

i'm trying to restart the interrupted thread in onResume (i'm interpreting the thread in onPause). For this i saw lot of examples in online but nothing was helpful (May it's my fault). So,please tell me how to restart interrupted thread in onResume

My code:

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();
}
}
Bahu
  • 1,516
  • 2
  • 28
  • 49
  • You can't restart a thread that has been interrupted. There are some good ideas on what you *can* do in the accepted answer here: http://stackoverflow.com/questions/1881714/how-to-start-stop-restart-a-thread-in-java – npace May 14 '16 at 11:08

1 Answers1

0

@npace Thank you, i got the idea from your comment. I restarted the interrupted thread in onResume like

@Override
protected void onResume() {
    super.onResume();
    runThread();
}
Bahu
  • 1,516
  • 2
  • 28
  • 49