How to restart Activity Created theme again and again

What I am doing is starting the stream, when the button is pressed inside the fragment, and in Back click, my activity and fragment will be destroyed, but when this activity and fragment are called again, I want to start my stream again from the previous state.

I know that I do not provide much information, but I am too much confused by what I ask.

So kindly help me.

Here is what i know

thread = new Thread(new Runnable() { @Override public void run() { while (runThread) { try { getActivity().runOnUiThread(new Runnable() { @Override public void run() { updateProgress(); } }); Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); break; } } } }); thread.start(); 

here is my onDestroy

 @Override public void onDestroyView() { // TODO Auto-generated method stub super.onDestroyView(); try { if (thread != null) { runThread = false; } else { } } catch (Exception e) { } } 
+5
source share
1 answer

It seems that the thread will not stop until it ends.

 thread = new Thread(new Runnable() { @Override public void run() { while (runThread) { try { getActivity().runOnUiThread(new Runnable() { @Override public void run() { //+ Hear if(runStat){ updateProgress(); } } }); Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); break; } } } }); @Override public void onDestroyView() { // TODO Auto-generated method stub super.onDestroyView(); try { if (thread != null) { runThread = false; runStat=false; } else { } } catch (Exception e) { } } @Override public void onStop() { // TODO Auto-generated method stub super.onStop(); runStat=false; } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); runStat=true; } 
+1
source

Source: https://habr.com/ru/post/1202402/


All Articles