title: how to start an activity which displays a UI screen to user while data is loaded in the main activity layout
body: <p>I am trying to load some data in the main activity layout from the database, while this happens I want to show the user a dialog in the popup. I have tried using thread and also async task but still the screen freezes while the data is being loaded and finally when it completes then it displays my popup. I want the dialog to display simultaneously with data load.
  below is the function from main activity that loads the data and calls the async task.</p>
  
  <pre><code>public void call_itemdisplay(final String bookid)
     {
        new waitAsync().execute();
        //load data from DB below
          }
  </code></pre>
  
  <p>The async task that starts a new activity</p>
  
  <pre><code>public class waitAsync extends AsyncTask&lt;Void, Void, Void&gt; {
      @Override
     protected Void doInBackground(Void... params) {
      try {
          Intent i = new Intent(MainActivity.mCon, waitActivity.class);
          MainActivity.mCon.startActivity(i);
  
      } catch (Exception e) {
          e.printStackTrace();
      }
          return null;
          }
  
  
  }
  </code></pre>
  
  <p>The Popup Activity that is started by the async task</p>
  
  <pre><code>public class waitActivity extends Activity {
      static waitActivity wact;
      public static Context wcon;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          wact=this;
  
          setContentView(R.layout.activity_wait);
      }
  
  }
  </code></pre>
  
  <p>Need help in showing the POPup activity in the UI while data loads in the main activity. Currently the screen freezes while loading data and then show all together after loading is complete</p>
  
  <p>EDITED with new changes: The async task</p>
  
  <pre><code>public class waitAsync extends AsyncTask&lt;String, Void, String&gt; {
      ResultSet rs=null;
     private ProgressDialog processingDialog;
      static Connection conn=null;
      Statement stmt;
     // waitThread wt= new waitThread();
      @Override
      protected void onPreExecute() {
        //  ProgressDialog processingDialog;
          super.onPreExecute();
          processingDialog = new ProgressDialog(MainActivity.mCon);
          processingDialog.show();
          processingDialog.setContentView(R.layout.activity_wait);
          //processingDialog.setMessage("Loading...");
  
      }
      @Override
     protected String doInBackground(String... params) {
          try {
  
  
              String driver = "net.sourceforge.jtds.jdbc.Driver";
              String ip = "mfb.dfsdfsdf.ap-north-1.rds.amazonaws.com";
              String classs = "net.sourceforge.jtds.jdbc.Driver";
              String db = "MyDatabase";
              String un = "xxxwww";
              String password = "xxxxxx";
              Class.forName(classs);
  
              String ConnURL = null;
              ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
                      + "databaseName=" + db + ";user=" + un + ";password="
                      + password + ";";
              conn = DriverManager.getConnection(ConnURL);
  
              stmt = conn.createStatement(
                      ResultSet.TYPE_SCROLL_INSENSITIVE,
                      ResultSet.CONCUR_READ_ONLY);
              rs=stmt.executeQuery(params[0]);
              int size = 0;
  
  
              //conn.close();
              MainActivity.getdata=rs;
              MainActivity.flag=1;
              //Thread.sleep(5000);
          } catch (Exception e)
          {
              Log.w("Error connection", "" + e.getMessage());
          }
          return null;
          }
      @Override
      protected void onPostExecute(String s) {
          super.onPostExecute(s);
          processingDialog.dismiss();
        //  wt.interrupted();
  
  
      }
  
  
  
  }
  </code></pre>
  
  <p>The call of async task from Main_Activity</p>
  
  <pre><code>Getdata(String bookid)
  {
    String SQL="Select eb.book_name,eb.AuthorID,ma.Name,eb.GenreID_M,eb.GenreID_D,gm.Genre_MN+'- '+gd.Genre_DN as Genre,isnull(eb.pubDate,'') pubDate,isnull(eb.book_Loc,'') book_Loc,\n" +
                      " eb.Price,eb.ico_Loc,eb.Descrip from Master_ebook eb inner join Master_Author ma on eb.AuthorID=ma.Author_ID\n" +
                      " inner join Master_Genre_M gm on eb.GenreID_M=gm.Genre_MID\n" +
                      "inner join Master_Genre_D gd on eb.GenreID_D= gd.Genre_DID where eb.bookID=" + bookid;
  
  
              new waitAsync().execute(SQL);
  
              int c=0;
              while(MainActivity.flag==0)
              {
                  c++;
              }
  
              if(MainActivity.flag==1)
              {
                  MainActivity.flag=0;
                  //processingDialog.dismiss();
              }
  
              ResultSet rs=MainActivity.getdata;
  }
  </code></pre>