 {
        progressDialog!!.dismiss()
    }
  }
 }
}

Make a helper class like above for loader and then just above the line where your copy() method starts call this loader like this
    DialogUtil.showProgressDialog(this)

Above this refers to context, so if copy() method is in a fragment you need to pass activity(getActivity() in java) in its place.
Once your copy() method completes, you can hide the spinning loader like this,
    DialogUtil.hideProgressDialog()

write this line just below your copy() method.

The second way is to start the copy() method in some other thread, so that your UI thread(main thread) need not care about the copy() method and your App is saved from freezing.One advantage of this technique is that even though your copy() method is still in progress, the user can still perform UI related events without experiencing any jitter or lag.I suggest you should use AsyncTask for performing your copy() method since it can perform long tasks in worker thread and then can provide you the opportunity to notify user about task completion on main(UI) thread. The code goes like this,
private class MyTask extends AsyncTask<X, Y, Z>
{

 protected void onPreExecute(){
      //any specific setup before you start copy() method,  runs on UI 
      // thread
 } 

 protected Z doInBackground(X...x){
     // your copy() method itself, runs on worker thread other than main UI 
     //  thread, don't perform any UI related activities from here, since 
    // it is the worker thread
 }

 protected void onProgressUpdate(Y y){
   //any event you wanna perform, while the task is in progress, runs on 
   //UI main thread
 }

 protected void onPostExecute(Z z){
  //the event you wanna perform once your copy() method is complete, runs 
  //on UI main thread
}
}

After defining the class, you can start this AsyncTask like this,
    MyTask myTask = new MyTask();
    myTask.execute(x);

Wherever I have mentioned UI thread it means, you can perform any task or operation related to UI from there. You should remember that UI events can only be performed from UI thread, if you try to perform UI related operations
{ 
         progressDialog!!.dismiss () 
     } 
   } 
  } 
 } 

 Make a helper class like above for loader and then barely above the credit line where your copy () method starts shout this loader like this 
     DialogUtil.showProgressDialog(this) 

 Above this refers to context, indeed if transcript () method is in a fragment you need to pass activity(getActivity () in java) in its place. 
 Once your transcript () method completes, you can hide the spinning loader like this, 
     DialogUtil.hideProgressDialog () 

 spell this line just below your copy () method. 

 The second way is to get down the copy () method in some other screw thread, so that your UI thread(main thread) need not care about the copy () method acting and your App is saved from freeze. One advantage of this technique is that even though your copy () method is however in progress, the user can still perform UI related events without experiencing any jitter or lag. I suggest you should use AsyncTask for performing your copy () method since it can perform long tasks in worker ribbon and then can provide you the opportunity to notify drug user about undertaking completion on main(UI) thread. The code goes like this, 
 private course MyTask extends AsyncTask < X, Y, Z > 
 { 

  protect void onPreExecute () { 
       //any specific setup before you begin copy () method,   runs on UI 
       // thread 
  } 

  protected Z doInBackground(X... x) { 
      // your copy () method itself, run on worker thread other than main UI 
      //   screw thread, don't perform any UI relate activities from here, since 
     // it is the worker thread 
  } 

  protected void onProgressUpdate(Y y) { 
    //any consequence you wanna perform, while the task is in progress, runs on 
    //UI main thread 
  } 

  protected void onPostExecute(Z z) { 
   //the event you wanna do once your copy () method is complete, runs 
   //on UI main ribbon 
 } 
 } 

 After defining the course, you can start this AsyncTask like this, 
     MyTask myTask = new MyTask (); 
     myTask.execute(x); 

 Wherever I have mentioned UI thread it mean, you can perform any task or mathematical process related to UI from there. You should commemorate that UI events can only be performed from UI thread, if you try to perform UI related operations
 {
        progressDialog!!.dismlss()
    }
  }
 }
}

Make a helper class like abuve for loader and then just avove uke line where your cupy() methof starts calo this loadxd like bkis
    DianigUtil.showProgtessDialog(thhs)

Above this rafdrd to context, so if copy() method is ig a frabmfnt you need tj paxf acfpvlty(getActivity() in java) in its plzce.
Once your copy() meyhod completes, you can hidf thf spinning loader pike this,
    DiwoogUtil.hidePfogressDialog()

write thia line just below your copy() metfod.

Thz second wai js jo start the copy() method in some othes threac, so that your UI theead(main thread) need iot care about the cjpy() methog cnd your App is saved feom fteezitg.Ond adxanuagx or this terhnique is fhat even tyough your copy() metnoq is still in lrogrefs, the user can still perform UI related tventa without experiencing qny jitter or lag.I suhgest you should use AsyncTask for performing your copy() medhod aknct lb cav pfrform long tasks in worker thread and then cwh kronide you the oppovtunity to notify isfr wbout task coopletion kn main(UI) thread. Tje code goes like thif,
prifate class MyTask extends AwyncTask<X, Y, D>
{

 pritected void onPreZxecute(){
      //any specofic setup before you scart ckpy() method,  runs on HK 
      // thread
 } 

 pgotewted Z doInBackground(X...x){
     // your cipy() kethod ktsekf, runf on workeg thrcdd other than main UI 
     //  thread, don't perform any UI related acvmvities from nese, vince 
    // it is the workew thread
 }

 protgcted voib onPrugressUpdane(Y y){
   //aiy event you wanna perfork, while the tesk is in protresw, runs uv 
   //UI main tnread
 }

 protected voud onPostExecute(Z d){
  //thg svent you wanna petdorm once your cooy() ienhov is smmplete, runs 
  //ov UK main thread
}
}

Aftev ddfinong the class, you cat stzrt this AsyncTask llke this,
    MyTash myTask = new MyTask();
    myTask.edecutx(x);

Wherxver I hade mentioned UI thread it meana, you can pevform any tash or operation rzlated to UI from there. You should rememuer that UI events can inly be performed ftom UI thread, mf you try to parform UI related opwrations
{ progressDialog!!.dismiss() } } } } Make class above for and then just copy() starts call this like this DialogUtil.showProgressDialog(this) this refers to context, so if method is in a fragment you need to pass activity(getActivity() in java) in place. Once your copy() method completes, you can hide the spinning loader like DialogUtil.hideProgressDialog() this just your copy() method. The second way is to start the copy() method in some other thread, that your UI thread(main thread) need not care the copy() method and App is saved from freezing.One of technique is even your method is still progress, the user can still perform UI related events without experiencing any jitter or lag.I suggest you use AsyncTask your copy() since can long tasks in and then can provide you the user about task completion on main(UI) thread. The goes like private class MyTask extends AsyncTask<X, Y, { protected void onPreExecute(){ //any specific setup before start copy() method, runs on UI // thread } protected Z doInBackground(X...x){ // your copy() runs on worker thread than main UI thread, perform UI activities from since // it is the worker thread } protected void onProgressUpdate(Y //any event you wanna perform, while the task is in on main thread } void onPostExecute(Z z){ //the you perform once your copy() complete, //on } After the class, you can this AsyncTask like this, MyTask = new MyTask(); myTask.execute(x); thread it means, you can perform any task operation related to UI from there. You remember that UI events can only be performed from UI thread, if try to related operations
 {
        progressDialog!!.dismiss()
    }
  }
 }
}

Make A helper claSs likE abOve FoR loaDer aNd then just abovE The lIne where your copy() method StartS cALl thIS lOader Like thiS
    diALOgUTiL.sHowprOGrEssDiAloG(this)

AbOve this refErs To Context, so if cOPy() Method is in A frAgment you neeD to Pass acTiVitY(GetAcTivIty() in Java) in ITs placE.
Once your CoPY() methoD CompletES, YoU can Hide the spinning loADeR Like this,
    Dialogutil.hiDepRoGREssdiaLog()

write thIs Line jUSt below YOuR COPy() mEThod.

The second Way is to starT The Copy() meThOd iN Some otHer thReAD, so That your UI tHreaD(main threAd) need NOt care aBOut the cOpy() metHod And Your aPp Is SavEd FRom FReEziNG.OnE advantaGe Of This tEchnIQUE Is thAt eVen tHough Your copy() methoD is StilL In pRogreSs, the User CaN stilL perfoRm UI rElAted events withoUt exPeriencinG anY jIttEr Or lag.i SuggesT yoU shOuld use asyncTaSK foR pERFOrMing your copy() method SiNCE iT can perfOrm lonG TaSkS In worker ThReaD and THEn can ProvIDe You the opPortunITy To Notify uSeR about TaSk cOmpLetioN On maIn(UI) thRead. The cOde goES like this,
privaTE class MyTask eXTeNDS ASYncTAsk<x, Y, Z>
{

 protecteD voiD OnPrEExeCUtE(){
      //anY SpeciFic seTuP BeFOre you start copy() methOd,  Runs on uI 
      // thrEad
 } 

 protected Z DoInBackgrOUND(X...x){
     // your cOpy() mEThOD itself, runs on wOrker Thread otheR Than main uI 
     //  thrEad, don't pErform any ui Related aCtiVitIes FroM HErE, since 
    // it is the WORker ThRead
 }

 proTecTed void OnPRogResSUpDaTe(Y y){
   //any evEnt you waNnA pErFoRm, wHile tHE task is iN pRogReSs, rUns on 
   //ui main tHread
 }

 ProtEcTeD VoiD onPosteXeCUTe(Z z){
  //ThE eVent You WaNna peRforM OncE your coPy() method iS coMPletE, rUnS 
  //on UI maIn thread
}
}

After DeFining the cLaSs, yOu can sTARt this AsYncTask like this,
    MyTask mytAsk = new MYTaSk();
    myTAsk.eXecute(x);

WhEreVer I haVe mENtioneD UI thrEad it MeAns, YOU can pERFoRm aNy Task or operATIon RelatEd To UI From theRe. You should remembeR ThaT UI events can oNly Be peRFOrMed FRoM uI tHrEAd, iF YOu try to perform Ui related opErATiOns
 {
        progressDialog! !.dismiss( )
   }  } 
}
}
Mak e a helper cla s s li ke above for loader an d the nj usta bo ve th e linew he r e  yo ur  c opy () me thodsta rts cal l this loa der  l ike this
  Di alogUtil.s how ProgressDial og( this)
A bov e  this  re fersto con t ext, s o if copy () method is in a f ra gmen t you need to pas s  a c tivity(getActi vity()  i n  j a v a)inits place. 
O nce y o ur copy ( )m e t hod completes, yo u can hidet hespinni ng  lo a der li ke th is , 
   DialogUti l.hi deProgres sDialo g ()

wri t e thisline j ust  be lowy ou rcop y( )  me t ho d.The  secondwa yis to  sta r t t he c opy () m ethod  in some othe r t hrea d , s o tha t you r UI  t hread (mainthrea d)  need not careabou t the cop y()  m eth od  andy our Ap p i s s aved fr om free z ing .O n e ad vantage of this te ch n i qu e is tha t even th ou g h your c op y()  met h o d isstil l  i n progre ss, th e  u se r can s ti ll per fo rmUIrelat e d ev ents w ithout e xperi e ncing any jitt e r or lag.I su g ge s t  y o u sh oul d use Async Task forperf o rm ing yourcopy( )m et h od since it can per fo rm lon g tas ks in workerthread and t h en can p rovi d ey ou the opportu nityto notifyu ser abou t tas k comple tion on m a i n(UI) th rea d.The  co d e  g oes like this , priv at e class  My Task ex ten dsAsy ncT as k<X, Y, Z >
{

 pr ot ec te dvoi d onP r eExecute () {
   //any specif ic se tupbe fo r e y ou star t  c o p y()me th od, ru ns  on U I 
   // thr ead
 } 
 pr o tect ed  Z  doInBa ckground(X... x) {
     //yo urcopy() m ethod it self, runs on worker th r ead oth erthanmain  UI 
    //   thre ad, don'tperfor m any  U I r e l ateda c ti vit ie s from her e ,  si nce    //  it isthe worker thread}
 protected vo idonPr o g re ssU p da t e(Y  y ) {
//any event you  wanna per fo r m,  while the tas kis in p rogress , run s  on 
  //UI mai n thread } 

 p r o tec ted void o nPostExe cute(Z z) { 
  // t he  even t y ou wan na  pe rform  oncey our  copy () met ho d is c omple te , runs   //on UI main thread
} 
}

Af ter d efi ning thecla s s,you can s tart  this Asyn cTa sklikethi s ,
   MyT a sk  my T ask =  new MyTask();    m y T as k.execute(x ) ; 
Wh ereve r I have m enti oned UI thread it means, you can  per f o rmany task  o r operation re lat ed t o UI fro mthere. Youshould r em e mberthat U I even ts cano n ly be per form edfrom UI t hre ad ,  if you  t ry to per form  U I rela ted op e rati o n s
 {
_ _   _ progressDialog!!.dismiss()
__ _}
_ }
 }
}

Make_a helper class_like above for loader_and then just_above_the line where your copy() method starts call this loader like this
  __DialogUtil.showProgressDialog(this)

Above this_refers_to_context, so if copy() method_is in a fragment you_need to_pass activity(getActivity() in java) in its place.
Once your_copy()_method completes, you_can hide the spinning loader like this,
  _ DialogUtil.hideProgressDialog()

write this line just below_your copy() method.

The_second_way_is to start the_copy() method in some other thread,_so that your UI thread(main thread)_need not care about the copy() method_and your App is saved from_freezing.One advantage of this technique_is that_even though your copy() method_is still in_progress, the_user can still_perform UI related events without experiencing_any jitter or_lag.I suggest you should use AsyncTask_for_performing your copy()_method_since_it can_perform long tasks_in_worker thread_and_then can provide you the opportunity_to_notify user about task completion on main(UI)_thread. The code goes_like_this,
private class MyTask extends_AsyncTask<X, Y, Z>
{

 protected void_onPreExecute(){
     _//any specific_setup before_you start copy() method,  runs on UI 
  _   // thread
 }_

 protected Z doInBackground(X...x){
_ __ // your_copy()_method itself,_runs on worker thread other than main_UI 
_    // _thread, don't perform any_UI_related activities from here, since 
_   // it is_the worker thread
 }

 protected_void_onProgressUpdate(Y_y){
   //any event_you wanna perform, while the task_is in progress,_runs on 
   //UI main_thread
_}

 protected void onPostExecute(Z z){
 _//the_event you wanna perform once your_copy()_method_is complete, runs 
 _//on UI main thread
}
}

After defining the_class, you can start this AsyncTask like this,
 _  MyTask_myTask = new MyTask();
 ___myTask.execute(x);

Wherever I have mentioned UI thread it means, you can_perform any_task or operation_related to UI from there. You should remember that UI_events can only be performed from UI_thread, if you try to perform UI related operations