Displaying a progress bar during a network call

I want to show a progress bar during a web service call. I called the progress bar before the service call, but it is called after the service call is completed, and I got a response.

ProgressDialog dialog = ProgressDialog.show(LogIn.this,"","Loading. Please wait...", true); status=Loginvalid(method,username,psword); //calling the method for making service call 

But the execution dialog starts after receiving a response from the service. Please, how can I fix this problem.

+4
source share
3 answers
  public class Progress extends AsyncTask<String, Void, Void> { protected void onPreExecute() { ProgressDialog dialog = new MyProgressDialog(MyActivity.this, "Loading.. Wait.."); dialog.show(); } @Override protected Void doInBackground(String... params) { // TODO Auto-generated method stub // do your network connection return null; } protected void onPostExecute(Void unused) { dialog.dismiss(); } } 
+3
source

Use AsyncTask . This is the most efficient and painless way to display a progress dialog during a web service call.

show the progress panel in preexecute mode, call your web service in doInBackground and release the progress panel onPostexecute.

http://developer.android.com/reference/android/os/AsyncTask.html

+2
source

To correctly show the execution dialog, it must be executed in UIThread, and all other work ( service call ) in another. See an example here .

0
source

Source: https://habr.com/ru/post/1339136/


All Articles