How To Execute An Instruction/method Immediately After Progressdialog Dismisses?
I am trying to execute the method doSomeWork(); after the ProgressDialog dismisses in my method printing();which seems to be overlapped by the other method and the dialog is not sh
Solution 1:
This is one of the purposes of an AsyncTask
. It would look similar to this:
publicvoidonClick(final View v) {
newAsyncTask<Void, Void, Void>() {
@OverrideprotectedvoidonPreExecute() {
//Show your progress dialog in heresuper.onPreExecute();
}
@OverrideprotectedVoiddoInBackground( Void... params ) {
printing();
returnnull;
}
@OverrideprotectedvoidonPostExecute( Void result ) {
//Dismiss your progress dialog heredoSomeWork();
}
}.execute();
}
Solution 2:
Instead of using thread you can use asynchronous task. Show the progress dialog in the preexecute method call the printing method inside the background method after completing printing operation call the doSomeWork() inside the postexecute method.
Solution 3:
You can use Handler
for that in android. for example consider the following piece of code. you can dismiss the dialogs inside handlers. may it work for you.
privatevoidprinting(){
ThreadreceiptPrint=newThread(newRunnable() {
@Overridepublicvoidrun() {
retrieveEmails();
runOnUiThread(newRunnable() {
@Overridepublicvoidrun() {
try{
//here your code executes//after code executes do following:
uiHandler.sendEmptyMessage(0);
}catch(Exception ex){
errorHandler.sendEmptyMessage(0);
}
}
});
}
});
receiptPrint.start();
}
finalHandleruiHandler=newHandler() {
@OverridepublicvoidhandleMessage(Message msg) {
//here execute doSomeWork()
}
};
finalHandlererrorHandler=newHandler() {
@OverridepublicvoidhandleMessage(Message msg) {
//do other stuff
}
};
Post a Comment for "How To Execute An Instruction/method Immediately After Progressdialog Dismisses?"