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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:00:27+00:00 2026-05-27T18:00:27+00:00

I am using a simple function OnActivityResult, but it is not returning me desired

  • 0

I am using a simple function OnActivityResult, but it is not returning me desired results.

Please see my code and tell me where i am doing wrong.

public void OnClickFunction(View view)
{
    Intent intent = new Intent(getApplicationContext(), Second.class);
    startActivityForResult(intent, RESULT_OK);

///     My actions. . . 
}    

Then in the Second class, i have set Result like this:

Button.setOnClickListener(new OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            ValueOne = EditText.getText().toString().trim();
            if (ValueOne.equals(String.valueOf(Answer)))
            {
                Toast.makeText(getApplicationContext(), "Correct Answer", 0).show();
                Second.this.setResult(RESULT_OK, null);
                Second.this.finish();
            }
            else
            {
                Toast.makeText(getApplicationContext(), "Wrong Answer", 0).show();
            }
        }
    });    

Now coming back to the first.class, from where the Intent was called:

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
//      if (requestCode == RESULT_OK)
//      {
        if (resultCode == RESULT_OK)
        {
                             /////  MyActions. . . 
        }
//      }
}    

The debugger is not debugging this function, so the desired results are not coming.
Where i am doing wrong??

  • 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-27T18:00:28+00:00Added an answer on May 27, 2026 at 6:00 pm

    You have to destroy the second activity. Try pressing back button. I am able to see all the log messages in onActivityResult

    First Activity

    public class FirstActivity extends Activity {
    /** Called when the activity is first created. */
    int result = 100;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Intent i = new Intent(this,SecondActivity.class);
        startActivityForResult(i, result);
    }
    @Override
    protected void onActivityResult (int requestCode, int resultCode, Intent data) {
        Log.i("H", "RequestCode:" + requestCode);
        Log.i("H", "ResultCode:" + resultCode );
    }
    }
    

    SecondActivity

    public class SecondActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setResult(RESULT_OK);
        Log.i("S","Exiting Second Activity");
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the simple jQuery DIV refresh code. var refreshId = setInterval(function() { $('#refreshdash').load('dashboard.php?cache=');
I'm trying to implement a simple function using jqGrid, but it doesn't seem to
I am using this code for tooltips, a simple function I wrote to display
Background: I recently completed a tic-tac-toe game in AS3, using some simple function-based code
I'm a newbie using OpenMP with C++. I was doing a simple function, loading
I'm using this simple function: def print_players(players): tot = 1 for p in players:
iam using a simple insert script function to pass the values from registration html
I've written this very simple function to replace a file extension using LINQ in
Are there conventions for function names when using the Perl Test::More or Test::Simple modules?
Hay I'm using PHPMailer to send some simple emails, however the function SetFrom() doesn't

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.