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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:03:53+00:00 2026-05-31T19:03:53+00:00

I am having using onActivityResult method in my ParentActivity and i call a ChildActivity

  • 0

I am having using onActivityResult method in my ParentActivity and i call a ChildActivity from my ParentActivity in a Button click. In my ChildActivity when I click the default back button and when it goes to my ParentActivity , I am not getting my requestCode that i set in my ChildActivity in onStop() method by:

setResult(2);

How can I return my requestCode from my ChildActivity to ParentActivity when I click back button.

Here is my code:

      //Parent activity
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            Toast.makeText(this,resultCode+"", Toast.LENGTH_LONG).show();
            if(resultCode==2){
                finish();
            }
        }
    
    //Child activity
      protected void onStop() {
           setResult(2);
           super.onStop();
            }
 protected void onPause() {
           setResult(2);
           super.onStop();
            }
  • 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-31T19:03:54+00:00Added an answer on May 31, 2026 at 7:03 pm

    You can use this code in your child activity

    @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if(keyCode == KeyEvent.KEYCODE_BACK){
                setResult(RESULT_OK);
                finish(); // If you have no further use for this activity or there is no dependency on this activity
                        return true;
            }
            return super.onKeyDown(keyCode, event);
        }
    

    This piece of code will return result ok code from your child activity to parent activity

    Now in your parent activity in

    @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            switch (requestCode) {
            case 2:
                if(resultCode == -1){
                    // Here you write your code which you have to write on result receive
                }
                break;
    
            default:
                break;
            }
            super.onActivityResult(requestCode, resultCode, data);
        }
    

    Let me know if this helps you

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

Sidebar

Related Questions

I am having problems using SOAP in XE/XE2 from a thread. (I didn't test
I am having trouble using the link_to_remote method while rendering a layout. For example
I'm having problems using substr() with matches coming from a regular expression (using preg_match()
I'm having trouble using Simple Xml Serializer to build a Message from a complex
I'm having trouble using Rhino Mocks to assert that a method was called (and
I'm having difficulty using data created with canvas's todataurl() method. Currently my code sends
I am having troubles using shift() to call functions I have put in an
I am wondering what experiences people are having using the ASP.NET MVC Framework? In
Im having trouble using a .NET COM in vb6, It compiles ok and I
I'm having problems using textures that are larger than the OpenGL window or the

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.