Progressdialog Not Shown When Asynctask.Get() Called

Progress Dialog not showing during a asynctask call

Call "super.onPreExecute();" and "super.onPostExecute(result);" after your code for progress dialog. Or better, get rid of them (if you don't have reasons for calling them).

Use the following code:

private class runningMan extends AsyncTask<Void, Void, Integer>
{

@Override
protected void onPreExecute() {

Log.d("Runningman: ", "Started running");
//this method will be running on UI thread
progress = ProgressDialog.show(PromotionMain.this, "Loading", "PleaseWait", true);
super.onPreExecute();

}
@Override
protected Integer doInBackground(Void... params) {
//parse the JSON string
JSONParser jp = new JSONParser();
try {
Log.d(username , password);
jp.parsesData(promos, myJson, pictureArray, pathArray, labelArray);
Log.d("Runningman: ", "Finished parsing");
} catch (IOException e) {
e.printStackTrace();
}

return 1;
}
@Override
protected void onPostExecute(Integer result) {
ArrayList<ListItem> listData = getListData();
fillListView(listData);
Log.d("Runningman: ", "Finished runing");
//this method will be running on UI thread
progress.dismiss();
super.onPostExecute(result);
}

}

ProgressDialog not shown when AsyncTask.get() called

Yes, get() waits if necessary for the computation to complete, and then retrieves its result. This means, that you are blocking your UI thread, waiting for the result.

Solution: Don't call get

Usually, you will call a function (callback) in the postExecute.

Android: ProgressDialog not showing in AsyncTask called in onCreate()

Take your pDialog.dismiss(); into the your timer thread.

Reason: onPostExecute() immediately call because on background task is finished.

Its seprate thread which is on delay so cursor move to the onPostExecute()

 private class testAsync extends AsyncTask<Void, Void, Void> {
private ProgressDialog pDialog;

@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this); // tried with context, no difference
pDialog.setTitle("Inserting sample data");
pDialog.setMessage("Please wait. This dialog will be dismissed upon completion.");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}

@Override
protected Void doInBackground(Void... params) {
// TableControllerReadings TCR = new TableControllerReadings(context);
// TCR.insertSampleData(getApplicationContext());

new Timer().schedule(new TimerTask() {
@Override
public void run() {
//delay for 5 seconds
pDialog.dismiss();
}
}, 5000);

return null;
}

@Override
protected void onPostExecute(Void v) {
// pDialog.dismiss();
}
}

Progress Dialog not showing up in AsyncTask

Does anyone know why the dialog is not appearing on my activity?

Yes, the following line of code...

String filepath = fd.execute("http://myurl.com/img.png", PDFFileName, GameHistoryAdapter.this.gameInfo.toString()).get();

Don't EVER use the get() method of AsyncTask. It will block the main / UI thread and makes the whole point of an AsyncTask redundant. In other words get() turns it into a synchronous process instead of an asynchronous one.

The fact you can show a dialog in onPostExecute(...) is simply because it will be called after the blocking call to get() has returned. This means the main / UI thread will no longer be frozen (blocked) and UI updates can be made once again.

Remove get() from your call to execute(...) and instead just use...

fd.execute("http://myurl.com/img.png", PDFFileName, GameHistoryAdapter.this.gameInfo.toString());

...then in your onPostExecute(...) method set you filepath variable to what it should be.

I don't know who added the get() method to AsyncTask but if I ever find them I'll have some serious words to say. It has little or no use and causes a lot of people a lot of confusion.

AsyncTask get function not showing Progressbar

As mentioned, you should show ProgressDialog in onPreExecute method, and hide in onPostExecute(). Moreover, with progress = new ProgressDialog(this); you are only creating dialog, not showing. Try ProgressDialog.show(...) (https://developer.android.com/reference/android/app/ProgressDialog.html).

And, one more tip - don't do so much in onCreate (especially don't make any loops) - your app will show with a delay.



Related Topics



Leave a reply



Submit