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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:30:17+00:00 2026-05-23T21:30:17+00:00

I’m creating an application such that the user is in an Activity, and opens

  • 0

I’m creating an application such that the user is in an Activity, and opens up an AlertDialog.

Inside the alertDialog is a button that opens a second activity, waits for the result and fills a textfield in the alertDialog.

Well, at least it is supposed to.

Heres a snippit to better illustrate the problem:

private String mFillAddrField = "";
...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if(data == null) {
            ...
        } else {
            Bundle b = data.getExtras(); //DATA retrieved from second activity successfully
            mFillAddrField = b.getString("address");
        }
    }
}

...
public void displayAddScreen() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle("Create a new Grocery Store");
    alert.setMessage("Create a new store by filling out the form below.");

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.newstore_dialog, (ViewGroup) findViewById(R.id.nsd_root));

    final EditText nameField = (EditText) layout.findViewById(R.id.nsd_et_name);
    final EditText addrField = (EditText) layout.findViewById(R.id.nsd_et_address);
    final Button addrSelect = (Button) layout.findViewById(R.id.nsd_b_address);

    alert.setView(layout);

    addrSelect.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //Open MAPS API return me an address
            //Save address to text field
            Intent i = new Intent(getApplicationContext(), GroceryMapActivity.class);
            startActivityForResult(i,0);
            addrField.setText(mFillAddrField); //OFFENDING CODE HERE
        }
    });

My problem is that the call to addrField.setText comes before the activity is completed (probably before its started too!), how can I wait here until the activity returns a result, then continue the rest of the code (setting the text)?

  • 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-23T21:30:17+00:00Added an answer on May 23, 2026 at 9:30 pm

    Move addrField.setText() to your onActivityResult() method

    (You can’t stop and wait in the UI thread the way you seem to want to)

    I’ve changed the supplied code to make addrField a class member and move setting it to match what you want to do:

    private String mFillAddrField = "";
    EditText addrField;
    ...
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if(data == null) {
                ...
            } else {
                Bundle b = data.getExtras(); //DATA retrieved from second activity successfully
                mFillAddrField = b.getString("address");
                addrField.setText(mFillAddrField);
            }
        }
    }
    
    ...
    public void displayAddScreen() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    
    alert.setTitle("Create a new Grocery Store");
    alert.setMessage("Create a new store by filling out the form below.");
    
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.newstore_dialog, (ViewGroup) findViewById(R.id.nsd_root));
    
    final EditText nameField = (EditText) layout.findViewById(R.id.nsd_et_name);
    addrField = (EditText) layout.findViewById(R.id.nsd_et_address);
    
    final Button addrSelect = (Button) layout.findViewById(R.id.nsd_b_address);
    
    alert.setView(layout);
    
    addrSelect.setOnClickListener(new OnClickListener() {
    
        @Override
        public void onClick(View v) {
            //Open MAPS API return me an address
            //Save address to text field
            Intent i = new Intent(getApplicationContext(), GroceryMapActivity.class);
            startActivityForResult(i,0);
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.