Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8362041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:50:58+00:00 2026-06-09T11:50:58+00:00

I have two asynctask working with each other. I’m using them for creating Restaurant

  • 0

I have two asynctask working with each other. I’m using them for creating Restaurant menu. First web service gets menu’s titles from database. Second web service gets items of title from database. I get title data in my first asynctask and item data in my second asynctask.

For example, I have ten menu titles. There are eight items for each title. I execute first asynctask and get all of menu titles. I want to call second asynctask in first asynctask’s onPostExecute for get this title’s item and add TextView. I have to wait finished every second task for add item respectively.

In short, I need call first AsyncTask and wait finish it. Then send request to second AsyncTask in First AsyncTask. I have to wait every request to finish. How can I wait ?

Here is the my code.

First AsyncTask

public class BaslikDoldurAS extends AsyncTask<String,String[][],String[][]>{
        int ParamID;

        public BaslikDoldurAS(String ParamID){
            this.ParamID=Integer.parseInt(ParamID);
        }

        @Override
        protected String[][] doInBackground(String... params) {
            BaslikDoldur(ParamID);
            return sonuc;
        }

        protected void onPostExecute(String[][] sonuc){
            for(int i=0;i<baslikCount;i++){ 
                 MenuDoldurAS kontrol = new MenuDoldurAS(firma_id,sonuc[2][i]);
                 kontrol.execute();
            } 
        }
    }

my function which is used in first asyncTask

private String[][] BaslikDoldur(Integer ParamID){
        PropertyInfo id = new PropertyInfo();
        id.name= "id";
        id.setValue(ParamID);
        id.type = PropertyInfo.INTEGER_CLASS;

        SoapObject request = new SoapObject(NAMESPACE, "BaslikDoldur");
        request.addProperty(id);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut=request;
        envelope.dotNet = true;     
        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(MenuURL);
        androidHttpTransport.debug = true;

        try {

            androidHttpTransport.call("http://tempuri.org/BaslikDoldur", envelope);
            SoapObject response = (SoapObject) envelope.getResponse();

            sonuc[2]=new String[response.getPropertyCount()]; //baslik
            baslikCount=response.getPropertyCount();

            for(int i=0;i<response.getPropertyCount();i++){    
                   Object property = response.getProperty(i);
                   if(property instanceof SoapObject){
                       SoapObject menu = (SoapObject) property;
                       sonuc[2][i] = menu.getProperty("menu_baslik").toString();
                   }
            }
     } 
             catch (Exception e) {          
                e.printStackTrace();
            }
        return sonuc;

    }

Second AsyncTask

public class MenuDoldurAS extends AsyncTask<String,String[][],String[][]>{
        int ParamID;
        String Baslik;

        public MenuDoldurAS(String ParamID,String Baslik){
            this.ParamID=Integer.parseInt(ParamID);
            this.Baslik=Baslik;
        }
        @Override
        protected String[][] doInBackground(String... params) {
            MenuDoldur(ParamID,Baslik);
            return sonuc;
        }

        protected void onPostExecute(String[][] sonuc){
            for(int i=0;i<count;i++){
                String baslik="";
                if(!baslik.equals(sonuc[2][i])){
                    baslik=sonuc[2][i];
                    TextView basliktxt = new TextView(Urun.this);
                    basliktxt.setText(sonuc[2][i]);
                    basliktxt.setTextSize(20);
                    basliktxt.setTextColor(Color.RED);
                    basliktxt.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
                    urunLayout.addView(basliktxt);
                }
                else{
                    TextView aciklamatxt = new TextView(Urun.this);
                    aciklamatxt.setText(sonuc[3][i]);
                    aciklamatxt.setTextColor(Color.parseColor("#0c0c7c"));
                    aciklamatxt.setTextSize(17);
                    aciklamatxt.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
                    urunLayout.addView(aciklamatxt);
                }
            }   
        }

    }

my function which is used in second asyncTask

private String[][] MenuDoldur(Integer ParamID,String Baslik){
        PropertyInfo id = new PropertyInfo();
        id.name= "id";
        id.setValue(ParamID);
        id.type = PropertyInfo.INTEGER_CLASS;

        PropertyInfo baslik = new PropertyInfo();
        baslik.name= "baslik";
        baslik.setValue(Baslik);
        baslik.type = PropertyInfo.STRING_CLASS;

        SoapObject request = new SoapObject(NAMESPACE, "MenuDoldur");
        request.addProperty(id);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut=request;
        envelope.dotNet = true;     
        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(MenuURL);
        androidHttpTransport.debug = true;

        try {

            androidHttpTransport.call("http://tempuri.org/MenuDoldur", envelope);
            SoapObject response = (SoapObject) envelope.getResponse();

            sonuc[3]=new String[response.getPropertyCount()]; //aciklama ve fiyat
            count = response.getPropertyCount();

            for(int i=0;i<response.getPropertyCount();i++){    
                   Object property = response.getProperty(i);
                   if(property instanceof SoapObject){
                       SoapObject menu = (SoapObject) property;
                       sonuc[3][i] = menu.getProperty("menu_aciklama").toString() + " - " + menu.getProperty("menu_fiyat").toString();
                   }
            }
     } 
             catch (Exception e) {          
                e.printStackTrace();
            }
        return sonuc;   

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:51:00+00:00Added an answer on June 9, 2026 at 11:51 am

    If you want to wait until all AsyncTasks are done before proceeding, why don’t you just put all of you work in doInBackground of the first AsyncTask?

    Or you don’t want to do this because you want to run the 10 “second tasks” in parallel? (Which, incidentally you’re not doing anyway, because you’re not using the THREAD_POOL Executor for your tasks.) If this is the case then why not just do something like

    // variable accessible to both tasks
    ArrayList<AsyncTask> mRunningTasks = new ArrayList<AsyncTask>();
    // AsyncTask1
    protected void onPostExecute(String[][] sonuc){
        for(int i=0;i<baslikCount;i++){ 
             MenuDoldurAS kontrol = new MenuDoldurAS(firma_id,sonuc[2][i]);
             mRunningTasks.add(kontrol);
        }
        for (AsyncTask task : mRunningTasks) {
            task.execute();
        }
    }
    
    // AsyncTask2
    protected void onPostExecute(...) {
        boolean allComplete = true;
        for (AsyncTask task : mRunningTasks) {
          if (!task.getStatus().equals(AsyncTask.Status.FINISHED)) {
              allComplete = false;
              break;
          }
        }
        if (allComplete) {
           //do whatever
           mRunningTasks.clear();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two applications written in Java that communicate with each other using XML
In my application I have two threads (I'm using AsyncTask class). in doInBackground() method
I have two AsyncTask that are not working. There must be something in common
I have two total different implementations of AsyncTask , lets say AT1 and AT2
I have two spinners one named cuisine and other area. I m calling the
I have three simultaneous instances of an AsyncTask for download three files. When two
I have two activities; Home is my first activity and Settings is my second
In my app i have a processDialog (using AsyncTask) and at doInbackground it fetches
tl;dr: I have two threads, one of them serealizes object, and another tries to
I have a service which runs two asynctasks. One is for receiving multicast packets

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.