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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:04:24+00:00 2026-05-16T16:04:24+00:00

I am having trouble passing data from one activity to another. I can easily

  • 0

I am having trouble passing data from one activity to another.

I can easily use startActivityForResult() to send an intent with the original data and then manipulate this data in the new Activity. I then use setResult() in the onPause() function of this new Activity to return some data in the Intent object. Doing this calls onActivityResult() in the original Activity, but the Intent sent to this function always ends up null, which is wrong. I don’t understand why this Intent object is null.

Here are the main functions of the starting Activity, “Test”:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    // add some data to play with
    string_array_list.add("item1");
    string_array_list.add("item2");
    string_array_list.add("item3");

    Button start_button = (Button) findViewById(R.id.button);
    start_button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // start an activity to reverse the order of items in the list
            startFlip();
        }
    });       
}

private void startFlip() {
    // using a bundle isn't absolutely necessary, 
    // but useful in the real program
    Intent i = new Intent(this, Flip.class);
    Bundle extras = new Bundle();
    extras.putStringArrayList(STRING_ARRAY_LIST, string_array_list);
    i.putExtras(extras);

    startActivityForResult(i, FLIP_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    string_array_list.clear();
    switch(requestCode) {
        case FLIP_REQUEST_CODE: 
            if(data != null) { // RIGHT ANSWER
                Bundle extras = data.getExtras();
                string_array_list = extras.getStringArrayList(STRING_ARRAY_LIST);
            }

              // WRONG ANSWER, but the only answer I get
            else Log.d(TAG, "data is null"); 
    }   
}

And here are the main functions of the launched Activity, “Flip”:

@Override
public void onCreate(Bundle joy) {
    super.onCreate(joy);

    // retrieve the data from intent (or bundle)
    Intent i = getIntent();
    Bundle extras = i.getExtras();
    if(joy != null) oldList = joy.getStringArrayList(Test.STRING_ARRAY_LIST);
    else oldList = extras.getStringArrayList(Test.STRING_ARRAY_LIST);

    // reverse the list order
    for(int x = oldList.size() - 1; x >= 0; --x) 
        newList.add(oldList.get(x));
}

@Override 
public void onPause() {
    super.onPause();

    Intent data = new Intent(this, Test.class);
    Bundle extras = new Bundle();
    extras.putStringArrayList(Test.STRING_ARRAY_LIST, newList);
    data.putExtras(extras);

    setResult(Test.FLIP_REQUEST_CODE, data);
}
  • 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-16T16:04:25+00:00Added an answer on May 16, 2026 at 4:04 pm

    I then use setResult() in the onPause() function of this new Activity to return some data in the Intent
    object. Doing this calls onActivityResult() in the original Activity, but the Intent sent to this function
    always ends up null, which is wrong. I don’t understand why this Intent object is null.

    onPause() is too late. You should be calling setResult(), typically followed by finish(), based on some positive user action (clicking a list item, clicking a button, etc.).

    Also, please examine resultCode to see if you actually got a result. Right now, you’re ignoring it, which will cause your app to “fail” just because the user pressed the BACK button.

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

Sidebar

Related Questions

I am having trouble passing data read from a text file to another class
I am having trouble passing data retrieved from a $.post() function to use in
I am having some trouble with passing data of an array from one class
CakePHP Newbie :) I am having trouble accessing another controller and passing that data
I'm having trouble passing a variable defined in one class instance to another class
I am having trouble nailing down the best method for passing data from a
I'm having trouble with ASP.NET MVC and passing data from View to Controller. I
I am having troubles passing data from the controller to the model in opencart(1.5.3).
i'm still transitioning from as2 to as3, i'm having trouble with parsing XML data
I am having trouble passing the return value from TheMethod() to Main and displaying

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.