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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:47:37+00:00 2026-06-13T03:47:37+00:00

I have two activities a parent and a child activity but the child activity

  • 0

I have two activities a parent and a child activity but the child activity is also triggered by another activity. Now I want to return result from this child activity to the Parent activity ONLY when the child activity is triggered from this parent activity.

Is there any way the child can find out the caller activity (so that it does some calculations only for that caller activity). Is there any way I can avoid this:

intent.putExtra("caller", "MainActivity");
startActivity(intent);

I want this:

if (ParentActivity)
{  //do something and finish() }
if (AnotherActivity)
{  //do something more and finish() }
  • 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-13T03:47:38+00:00Added an answer on June 13, 2026 at 3:47 am

    Yes you can do that by using startActivityForResult() from the Parent activity that you chose to be the one handling the results.

    Launch an activity for which you would like a result when it finished.
    When this activity exits, your onActivityResult() method will be
    called with the given requestCode. Using a negative requestCode is the
    same as calling startActivity(Intent) (the activity is not launched as
    a sub-activity).

    Basically in the Parent activity you can do:

    Intent intent = ...
    startActivityForResult(intent, SOME_UNIQUE_INT_CODE);
    

    Then you have to define a method to handle the results which is onActivityResult()

    protected void onActivityResult(int requestCode, int resultCode,
                 Intent data) {
             if (requestCode == SOME_UNIQUE_INT_CODE) {
                  // do something
             }
         }
    

    Inside the child activity, you can set the result by using setResult(). There are two variants of this method one of them gives you the possibility to pass in some data.

    Please, read the documentation to find more about how to use it.

    EDIT:

    You can use: getCallingActivity() from the called activity to find which is the parent activity but that only works if you used startActivityForResult.

    Return the name of the activity that invoked this activity. This is
    who the data in setResult() will be sent to. You can use this
    information to validate that the recipient is allowed to receive the
    data.

    Note: if the calling activity is not expecting a result (that is it
    did not use the startActivityForResult(Intent, int) form that includes
    a request code), then the calling package will be null.

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

Sidebar

Related Questions

I have two activities. In first I come to the second activity from first
I have two activities, one is main and I have another activity called Test
I have two activities, Activity A and Activity B. I pass objects from Activity
I have two activities A, B . Now from A i call B by
I have two Activities. Activity A gets a large amount of information from the
This is my situation. I have two activities: ONE and TWO. In TWO activity
I have two projects with similar starting splash and menu activities, but the package
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have two activities; Home is my first activity and Settings is my second

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.