Reputation: 165
How to Dismiss Progress Dialog in android after completion of Background Process ?
I had tried on Google but not get specific solution as i want.
Here is my code :
private void next() {
String url = "http://10.0.2.2/final/studentrecord.php";
FetchDataTask task = new FetchDataTask(url);
dialog = ProgressDialog.show(this, "", "Fetching StudentList from Server...", true, true);
task.execute(url);
}
How can i do this ?
Upvotes: 1
Views: 807
Reputation: 5061
Use Handler and dialog.dismiss();
Define Handler object in your activity, from background post a message to handler with handler.sendMessage(msg);
and in activity where your dialog is defined implement Handler.Callback's handleMessage method
e.g. if you send message to handler like
Message msg = new Message();
msg.what = 1;
handler.sendMessage(msg);
then in handleMessage method
@Override
public boolean handleMessage(Message msg) {
if (msg.what == 1) {
dialog.dismiss();
}
return false;
}
Upvotes: 1
Reputation: 3104
make sure your dialog is accessible even after completion of task :-
you should do like this :-
create dialog in onPreExecute()
and dismiss it using dialog.dismiss()
in onPostExecute()
Upvotes: 0