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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:15:11+00:00 2026-06-10T10:15:11+00:00

Overview of Problem : ActivityA starts ActivityB with startActivityForResult . ActivityB sets its result

  • 0

Overview of Problem: ActivityA starts ActivityB with startActivityForResult. ActivityB sets its result using setResult and then starts ActivityC with startActivity. ActivityC then starts the singleTop ActivityA with the CLEAR_TOP flag set. I expect this to finish ActivityB and call ActivityA’s onActivityResult method. Unfortunately this method is not getting called upon the restart of ActivityA.


ActivityA Code: I have started an activity (ActivityB) with startActivityForResult() with the following code from ActivityA:

....
final Intent intent = new Intent(this, ActivityB.class);
startActivityForResult(intent, 0);   
....

The following code in ActivityA waits for the result:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == ACTIVITY_RESULT){ 
        doSomethingSpecial();
    }
}

ActivityB Code: I have a confirmation dialog. When the user clicks “Yes” they will set the Result of this activity, which

private void showConfirmationDialog(String message, final String username) {
    AlertDialog.Builder alert = new AlertDialog.Builder(this)
    .setMessage(message)
    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent(this, ActivityC.class);

            setResult(ActivityA.ACTIVITY_RESULT);

            startActivity(intent);
        }
    })
    .setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    alert.show();
}

ActivityC Code: When ready, the following code is called upon a button click in ActivityC:

private void startActivityA(){
    Intent intent = new Intent(this, ActivityA.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
}

I am expecting the doSomethingSpecial() function in ActivityA to be called, but this is not occurring.

NB: Just as an aside, if the ActivityB code is replaced, and instead of starting ActivityC from the dialog, finish() is called–i.e. ActivityC is never opened and B is simply closed, then doSomethingSpecial() is indeed called. Therefore this problem seems to stem from some lack of understanding of the functionality of the back stack and clear top.

Any assistance would be appreciated as to why this is not behaving as desired! I have come up with a number of hacks around this, but am most interested as to why this is occurring in order to improve my understanding of the activity stack.

  • 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-10T10:15:12+00:00Added an answer on June 10, 2026 at 10:15 am

    I think that from a user’s perspective it will feel very strange that you are “starting” a previous activity (A) from a later activity (C), instead of just “going back” to it.

    I believe you should start C from B with startActivityWithResult(). Then when activity C is done call finish(). In B’s onActivityResult() call setResult() and then finish().

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

Sidebar

Related Questions

Problem overview: When using Eclipse Ganymede with the Web Tools Platform the project gets
Problem Overview: My application has an enrollment form. Users have a habit of entering
Hi guys I'm a jquery noobie, just started jqueryUI Problem OverView: I'm trying to
I just started a graphical C++ course and I have problem getting an overview
Overview: I have an advancedDataGrid that I am using a GroupingCollection on and I
Overview I am using CompositeWPF to create an app using C#. This really should
Overview I am trying to get a photo feed on to my site using
Overview of the problem In jQuery, the order in which you bind a handler
Reward: Has been claimed. Overview: The code giving me the problem is deployed here:
First a short overview of my code, i hope its understandable: I have a

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.