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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:41:20+00:00 2026-06-04T16:41:20+00:00

Here is my first activity code from where I call the second Activity :

  • 0

Here is my first activity code from where I call the second Activity:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT){       
    startActivityForResult(new Intent("chap.two.Chapter2Activity2"),request_Code);          
  }    
  return false;
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == request_Code) {
    if (resultCode == RESULT_OK) 
      Toast.makeText(this,data.getData().toString(),Toast.LENGTH_SHORT).show();             
  }
}

And here is a code of chap.two.Chapter2Activity2:

Button n = (Button) findViewById(R.id.btn_OK);
n.setOnClickListener(new View.OnClickListener() {               
   @Override
   public void onClick(View v) {
     // TODO Auto-generated method stub

     Intent data = new Intent();
     //---get the EditText view---
     EditText txt_username =(EditText) findViewById(R.id.txt_username);
     //---set the data to pass back---
     data.setData(Uri.parse(txt_username.getText().toString()));
     setResult(RESULT_OK, data);
     //---closes the activity---
     finish();

   }
});

here I see that setResult(RESULT_OK, data) has two arguments but
onActivityResult(int requestCode, int resultCode, Intent data) has three and I want know how onActivityResult gets value for third parameter? How it works can anyone tell me? Why isn’t this error ?

  • 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-04T16:41:21+00:00Added an answer on June 4, 2026 at 4:41 pm

    When you call Activity.startActivityForResult(), you set the requestCode. Later, this request code is needed by onActivityResult() in order to determine what Activity is sending data to it. We don’t need to supply requestCode again on setResult() because the requestCode is carried along.

    The data is intent data returned from launched intent. We usually use this data when we set extras on the called intent.

    Consider this example:

    CALL SECOND ACTIVITY

    Intent i = new Intent(MainActivity.this, CheckActivity.class);
    startActivityForResult(i, REQUEST_CODE_CHECK);
    

    ON SECOND ACTIVITY, SET INTENT RESULT

    getIntent().putExtra("TADA", "bla bla bla");
    setResult(RESULT_OK, getIntent());
    finish();
    

    BACK TO FIRST ACTIVITY, ONACTIVITYRESULT()

    if(requestCode == REQUEST_CODE_CHECK && resultCode == RESULT_OK){
        text1.setText(data.getExtras().getString("TADA") );
    }
    

    There you go. You should now understand what is Intent data and how to set and fetch the value.

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

Sidebar

Related Questions

Here is the first part of my controller code: public class ControlMController : Controller
First off here is the code! <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
first post here, and probably an easy one. I've got the code from Processing's
I have following code: public class readSensorsData extends Activity implements SensorListener { /** Called
My first activity is creating a second activity within its onCreate: if (userName ==
Here's scenario: I have 2 activities and one service First activity is a landing
Possible Duplicate: Updating progress dialog in Activity from AsyncTask I am developing my first
First here's what I'm using and trying to do: the minimal setup for this
First Question in here :) (AS3) First off, how do I access a variable
This is my first here in Stackoverflow. So I just want to ask question

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.