I have a thread that starts several operations once, and I would like to stop it when the user cancels ProgressDialog .
public void run() {
This thread only works once, so I cannot implement a loop to check if it continues the thread.
Here is my ProgressDialog:
//Wait dialog m_dlgWaiting = ProgressDialog.show(m_ctxContext, m_ctxContext.getText(R.string.app_name), m_ctxContext.getText(R.string.msg_dlg_analyse_pic), true, //indeterminate true, new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { m_bRunning = false; } });
How do I not know how to stop the thread, would the flow of the loop through the loop be correct to make sure it still works, or is there a better way?
public void run() { int op = 0; while(m_bRunning) { switch(op) { case 0 : //operation 1 break; case 1 : //operation 2 break; case 2 : //operation 3 break; case 3 : //operation 4 break; } op++; } }
Even with this solution, if there are too many operations in the stream, it can be difficult to complete the sequence of operations. Is there a better way to achieve this?
source share