Note that there are some explanatory texts on larger screens.

plurals
  1. POProgress dialog is not displayed properly while navigating between tabs in android using AsyncTask
    text
    copied!<p>I hv 2 tabs in my application. when ever i click the 2nd tab i need to get the data from the server for tat i am using AsyncTask , every thing is working fine but the problem is with the progress dialog ie when i click on 2nd tab i need to show the progress dialog in 1 st tab ( Since 2nd tab is fetching the data from server call ) But progress dialog is displaying in 2nd tab which is not visible for me until server call finishes.</p> <p>Can any one help me on this , Thanxs a lot..</p> <p>AsyncTask code</p> <pre><code> package com.cmc.bizgateway.net; import java.util.List; import org.apache.http.message.BasicNameValuePair; import android.app.ProgressDialog; import android.content.Context; import android.os.AsyncTask; import android.util.Log; import android.widget.Toast; public class ProgressBarManager extends AsyncTask&lt;List&lt;BasicNameValuePair&gt;, String, String&gt; { List list1 = null; Context context; private ProgressDialog dialog = null; public ProgressBarManager() { super(); } public ProgressBarManager(Context context) { super(); } public void setProgressDialog(Context c) { dialog = new ProgressDialog(c); this.context = c; } private NetworkManager networkManager = new NetworkManager(); @Override protected String doInBackground(List... arg0) { // Log.v("in dobackground", "result"); String response = null; try{ response = networkManager.postWebService(arg0[0]); }catch(Exception e) { Log.v("", "exception in background " + e); Toast.makeText(context.getApplicationContext()," resId",4000).show(); } return response; } protected void onPreExecute() { // Log.v("in pre execute", "result"); this.dialog.setMessage("Loading. Please wait..."); this.dialog.show(); } /** * method is called after the work is done. * * @param success * result of #doInBackground method. */ // @Override protected void onPostExecute(String success) { // Log.v("in post execute", "result"); if (dialog.isShowing()) { dialog.dismiss(); } } } </code></pre> <p>In tabhost class i am writing code </p> <pre><code> secondTabSpec.setIndicator("Categories").setContent( new Intent(this, ProductCategoriesActivity.class)); </code></pre> <p>and in ProductCategoriesActivity class </p> <p>oncreate method i am using</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = this; ProgressBarManager p = new ProgressBarManager(); p.setProgressDialog(context); List&lt;BasicNameValuePair&gt; nameValuePairs = new ArrayList&lt;BasicNameValuePair&gt;( 3); nameValuePairs.add(new BasicNameValuePair("method", "\"" + "getCategoryList" + "\"")); nameValuePairs.add(new BasicNameValuePair("type", "\"" + "product" + "\"")); String result; try { result = p.execute(nameValuePairs).get(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload