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

  • Home
  • SEARCH
  • 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 8109383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:24:20+00:00 2026-06-06T01:24:20+00:00

I have a program that needs to… In Activity A , do some jobs

  • 0

I have a program that needs to…

  1. In Activity A, do some jobs
  2. Start up Activity B (a WebView), let user fills in some information, then collect the result
  3. Then finally process the data

Currently I set it up like this:

In Activity A:

... 
startActivityForResult(this, new Intent(ActivityB.class)); 
...

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    ...
    //get result from data, do something with it
    ...
}

This seems like an awkward approach because I need to split the task into many different parts. I need to handle the exceptions thrown in all parts and it is inconvenient doing it this way. Is there a better method?

Also, after step (3) above, I am going to repeat this step several times, each time posting the final result to a textview. I think that means I need to put them into an AsyncTask, but that makes it even more difficult (where should onActivityResult be put?).

  • 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-06T01:24:22+00:00Added an answer on June 6, 2026 at 1:24 am

    The simple answer is there is no other way. This is how it’s mean to be done in Android. The only thing, I believe, you’re missing is passing a request code to activity B. Without it, you wouldn’t be able to differentiate which other activity returned result to activity A.

    If you’re invoking different activities from your A, use different requestCode parameter when starting activity. Furthermore, you can pass any data back to activity B using the same Intent approach (ok, almost any):

    public final static int REQUEST_CODE_B = 1;
    public final static int REQUEST_CODE_C = 2;
    ...
    
    Intent i = new Intent(this, ActivityB.class);
    i.putExtra(...);    //if you need to pass parameters
    startActivityForResult(i, REQUEST_CODE_B);
    
    ...
    
    //and in another place:
    Intent i = new Intent(this, ActivityC.class);
    i.putExtra(...);    //if you need to pass parameters
    startActivityForResult(i, REQUEST_CODE_C);
    

    Then in your on ActivityResult:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch(requestCode) {
            case REQUEST_CODE_B:
                //you just got back from activity B - deal with resultCode
                //use data.getExtra(...) to retrieve the returned data
                break;
            case REQUEST_CODE_C:
                //you just got back from activity C - deal with resultCode
                break;
        }
    }
    

    OnActivityResult is executed on the GUI thread, therefore you can make any updates you want straight in here.

    Finally, in Activity B, you’d have:

    Intent resultIntent = new Intent();
    resultIntent.putExtra(...);  // put data that you want returned to activity A
    setResult(Activity.RESULT_OK, resultIntent);
    finish();
    

    I’m not sure why you need AsyncTask to handle results.

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

Sidebar

Related Questions

I have a FORTRAN 95 program that needs to make some calls to the
I have a program that needs to start on 1/1/09 and when I start
I have a program that needs to retrieve some data about a set of
I have a program that needs to update some internal data structures when the
I have a program that needs to connect to a server to gather some
I have a program that needs to run as a separate NT user to
I have a program that needs to run as a normal user most of
I have a program that occasionally needs to scan some directories recursively (an improvement
I have a program that needs several third-party libraries, and at the moment it
I have a program that needs a lot of memory and want to set

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.