Progressdialog Not Shown In Asynctask
I have a huge database (40MB) on an SDCard. I need fetch data, with LIKE in query, which is very slow. DB request takes about 5 seconds. Therefore, I need to do it asynchronously a
Solution 1:
I put the definition of the dialog into the AsyncTask Class and it works fine for me. Take a look at this exampel (You have to change NAMEOFCLASS in the name of your CLASS:
privateclassdoInBackgroundextendsAsyncTask<Integer, Integer, Void> {
final ProgressDialog dialog = new ProgressDialog(NAMEOFCLASS.this) {
@Override
protectedvoidonPreExecute() {
dialog.setCancelable(false);
dialog.setTitle(getString(R.string.daten_wait_titel));
dialog.setIcon(R.drawable.icon);
dialog.setMessage(getString(R.string.dse_dialog_speichern));
dialog.show();
}
@Override
protectedvoidonCancelled() {
dialog.cancel();
}
....
@Override
protected void onProgressUpdate(Integer... values) {
// DO YOUR UPDATE HERE
}
@Override
protected void onPostExecute(Void result) {
dialog.dismiss();
}
}
Solution 2:
Maybe this SO answer could help you. It looks like similar problem. Try to use AsyncQueryHandler for querying your database
Solution 3:
declare you Dialog box on Class (Activity) level like this
privateProgressDialogdialog=null;
show the progress dialog and call the AsyncTask class when you want to start you Busy work..like onButton click or any
dialog = ProgressDialog.show(this,"Sending Email to your account please! wait...", true);
SendingEmailTasktask=newSendingEmailTask();
Strings="";
task.execute(s);
create your inner class like
privateclassSendingEmailTaskextendsAsyncTask<String, Void, String> {
protectedStringdoInBackground(String... urls) {
//do your work here..// like fetching the Data from DB or anyreturnnull;
}
@OverrideprotectedvoidonPostExecute(String str) {
//hide progress dialog here
dialog.dismiss();
}
}
let me know if this help!!
Post a Comment for "Progressdialog Not Shown In Asynctask"