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 4088348
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:58:16+00:00 2026-05-20T18:58:16+00:00

public class classified extends Activity { private ArrayAdapter<String> aaagency ; String strdata=; String strerrormess=;

  • 0
public class classified  extends Activity
{
    private ArrayAdapter<String> aaagency ;
        String strdata="";
        String strerrormess="";
        public void onCreate(Bundle savedInstanceState) 
    {
        setTitle("Classified Ad. Booking");
                super.onCreate(savedInstanceState);
                this.setContentView(R.layout.classified);
        }
        public void srcAgency(View view) throws IOException
    {   
        Log.i("Classified Ad","srcAgency");
        new srcAgency().execute();
        srcAgency srcagen = new srcAgency();
        strdata = srcagen.strtempdata;

        Log.i("AgencyData2", strdata);
        Log.i("AgencyData3", strerrmess);
        if(strerrmess.equals(""))
        {
            strarr= fun1.split(strdata, "^");
            aaagency = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item , strarr); 
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Agency");
            builder.setAdapter(aaagency, new DialogInterface.OnClickListener() 
            {
                public void onClick(DialogInterface dialog, int item) 
                {
                    txtAgency.setText(strarr[item]);
                }
            });
            builder.show();
        }
    }

        class srcAgency extends AsyncTask<Void, String, Void> 
    {
        String strtempdata="";
        ProgressDialog dialog;
        @Override
        protected void onPreExecute() 
        {
            strerrmess="";
            super.onPreExecute();
            dialog = ProgressDialog.show(classified.this, "", "Please wait...", true);
            dialog.show();
        }

        @Override
        protected Void doInBackground(Void... unused) 
        {
            try
            {
                stragency = txtAgency.getText().toString().trim();
                intagencyBrac1= stragency.lastIndexOf('(');
                intagencyBrac2= stragency.lastIndexOf(')');

                if (stragency.length() < 3)
                {strerrmess="Please Enter atleast 3 Characters for Agency Searching";}
                else if(intagencyBrac1>=0||intagencyBrac2>=0)
                {strerrmess="Please Enter Characters for Agency Searching";}
                else
                {
                    if(stragency.indexOf(' ')!=-1)
                    {stragency = stragency.replace(' ', '!');}


                    Log.i("AgencyUrl",strurl);
                    strdata = "Client1^Client2^Client3^Client4^Client5^Client6^Client1";
                    Log.i("AgencyData",strdata);
                    strtempdata = strdata;
                    if(!strdata.equals(""))
                    {

                    }
                    else
                    {strerrmess ="No Data Available";}
                }
            }
            catch(Exception e)
            {

            }
            return null;

        }

        @Override
        protected void onPostExecute(Void unused) 
        {
            dialog.dismiss();
            if (strerrmess.equals("Please Enter atleast 3 Characters for Agency Searching"))
            {Toast(strerrmess);intflag=1;}
            else if(strerrmess.equals("Please Enter Characters for Agency Searching"))
            {Toast(strerrmess);intflag=1;}
            else if(strerrmess.equals("Your Session Got Expired. Please login again."))
            {
                Intent intent = new Intent(classified.this, loginscreen.class);
                startActivity(intent);
                Toast(strerrmess);
                intflag=1;
            }
            else
            {intflag=0;}
        }
    }
}

I am unable to get the value of strdata which i have initialized in asynctask function in the srcagency function. What should I do? Even though strdata is a global variable.

I have also tried this but I think you can’t initialize array adapter in onpostexecute function…

@Override
        protected void onPostExecute(Void unused) 
        {
            dialog.dismiss();
            if (strerrmess.equals("Please Enter atleast 3 Characters for Agency Searching"))
            {Toast(strerrmess);intflag=1;}
            else if(strerrmess.equals("Please Enter Characters for Agency Searching"))
            {Toast(strerrmess);intflag=1;}
            else if(strerrmess.equals("Your Session Got Expired. Please login again."))
            {
                Intent intent = new Intent(classified.this, loginscreen.class);
                startActivity(intent);
                Toast(strerrmess);
                intflag=1;
            }
            else
            {strarr= fun1.split(strdata, "^");
            aaagency = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item , strarr); 
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Agency");
            builder.setAdapter(aaagency, new DialogInterface.OnClickListener() 
            {
                public void onClick(DialogInterface dialog, int item) 
                {
                    txtAgency.setText(strarr[item]);
                }
            });
            builder.show();}
        }

Any help or comments would be appreciated.

Thanks

  • 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-05-20T18:58:17+00:00Added an answer on May 20, 2026 at 6:58 pm
     Log.i("Classified Ad","srcAgency");
     new srcAgency().execute();
     srcAgency srcagen = new srcAgency();
     strdata = srcagen.strtempdata;
    

    This does not work. You are saying, start an AsyncTask that will set your strdata at some point in the future but also immediately return and after creating a new AsyncTask have it know what the last AsyncTask did.

    Try this:

    void srcAgency(View v){ 
    //We only want to start the AsyncTask here, nothing else.
    // Whatever you did before and whatever triggered the srcAgency(View) method
    srcAgency srcagen = new srcAgency();
    srcagen.execute();
    return;
    }
    
    
    
    public void realSrcAgency(View v) {
    ... // The rest of original srcAgency(View)
    }
    
    // Inside of asyncTask srcAgency ... 
    public void postExecute() {
       // Call the new method we just had, but after our asyncTask is done.
      realSrcAgency(null);
    }
    

    Basically you can’t expect all these things to happen simultaneously. It would be easy to help you if you trimmed down the specifics of your code. It looks like you just want a button or some click to start an async task that fills a strings. However after that string is filled do something else with it. Also I don’t believe you need an async task for any of this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Offer_Popup extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.offer_popup); //newly
public class SettingsActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /*
public class BobDatabase extends SQLiteOpenHelper{ private static final String DATABASE_NAME = bob.db; private static
public class IdAsync extends AsyncTask<String, Void, Void> { AlertDialog alertDialog = new AlertDialog.Builder(MainClass.this).create(); protected
public class PackageTabActivity extends ListActivity{ HashMap<String,Object> hm ; ArrayList<HashMap<String,Object>> applistwithicon ; private static final
public class MainActivity extends Activity implements Runnable{ private int progressBarStatus = 0; private Handler
public class tryAnimActivity extends Activity { /** * The thread to process splash screen
public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new
public class A { private A(int param1, String param2) {} public static A createFromCursor(Cursor
public class HttpPostTask extends AsyncTask<Void, Integer, Void> { TextView txtStatus = (TextView)findViewById(R.id.txtStatus); @Override protected

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.