how to use Custom Progress bar in Asynk task in android -


public class loginactivity extends activity {      public static final int dialog_loading = 1;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_login);          showdialog(dialog_loading);         thread thread =  new thread(null, dosometask);         thread.start();      }       private runnable dosometask = new runnable() {         public void run() {             try {                 //code of task                 thread.sleep(10000);             } catch (interruptedexception e) {}             //done! continue on ui thread             runonuithread(taskdone);         }     };      //since can't update our ui thread runnable takes care of that!     private runnable taskdone = new runnable() {         public void run() {             dismissdialog(dialog_loading);         }     };    @override     protected dialog oncreatedialog(int id) {         switch (id) {             case dialog_loading:                 final dialog dialog = new dialog(this, android.r.style.theme_translucent);                 dialog.requestwindowfeature(window.feature_no_title);                 //here set layout of progress dialog                 dialog.setcontentview(r.layout.custom_progress_dialog);                 dialog.setcancelable(true);                 dialog.setoncancellistener(new dialoginterface.oncancellistener() {                     public void oncancel(dialoginterface dialog) {                         // todo auto-generated method stub                      }                 });                 return dialog;              default:                 return null;         }     }; 

using upper code able show custom progress bar set on thread specified time have asynk task below .

   class download extends asynctask<void,void,void> {     @override     protected void onpreexecute() {         super.onpreexecute();     }      @override     protected void doinbackground(void... voids) {         return null;     }      @override     protected void onpostexecute(void avoid) {         super.onpostexecute(avoid);     } } 

i want set here progress bar once in background finish progress bar should disappear.please suggest me

using asynctask, can show dialog in onpreexecute() , after downloaded data in onpostexecute() can dismiss it. start download task doinbackground().

public class download extends asynctask<void,void,void>{     private activity activity;     private static final int dialog_loading = 1;     public download(activity activity){          this.activity = activity;     }      @override     protected void onpreexecute() {         super.onpreexecute();         // before start download task         activity.showdialog(dialog_loading);     }      @override     protected void doinbackground(void... voids) {          // start dowanload task here          return null;     }      @override     protected void onpostexecute(void avoid) {         super.onpostexecute(avoid);         // after downloaded data         activity.dismissdialog(dialog_loading);     } } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -