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

  • Home
  • SEARCH
  • 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 6173899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:39:19+00:00 2026-05-23T23:39:19+00:00

In my App a certain result code is used to finish the whole App

  • 0

In my App a certain result code is used to finish the whole App when this is needed (i.e to finish all Activities which belongs to my App in the Activity stack). All Activities are started with startActivityForResult(). The result code is captured in onActivityResult() and is from there passed on to the next Activity in the Activity stack. This boils down to each Activity finishing itself when the certain result code is being used.

Works great.. in all cases except for one:

Consider an Activity stack consisting of A -> B -> A. The last A (right in the sequence) starts the procedure by finishing itself and setting the result code for finishing the other Activities as well. After B has finished and passed on the result code to the first A (left A in the sequence) it turns out onActivityResult() is not called.

It can be worth mentioning that onDestroy() has not yet been called for the topmost A in the stack (right A in the sequence) when the first A is reached.

How to fix or work round this issue?

  • 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-23T23:39:20+00:00Added an answer on May 23, 2026 at 11:39 pm

    It turned out this issue only appeared if the Activity was started from the menu written with the following code:

        private static final int MENU_ITEM_A = 0;
        private static final int MENU_ITEM_B = 1;
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
           menu.add(0, MENU_ITEM_A, 0, R.string.menu_item_a);
           menu.add(0, MENU_ITEM_B, 0, R.string.menu_item_b);
           return super.onCreateOptionsMenu(menu);
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
           intent = null;
    
           switch (item.getItemId()) {
           case MENU_ITEM_A:
              intent = new Intent(this, ActivityA.class);
              break;
           case MENU_ITEM_B:
              intent = new Intent(this, ActivityB.class);
              break;
           default:
              intent = null;
              Log.e(TAG, "Unkown menu item.");
           }
           if (intent != null) {
              intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
              startActivityForResult(intent,
                    ActivityHelper.AUTO_CLOSE_REQUEST_CODE);
           }
           return super.onOptionsItemSelected(item);
        }
    

    Here are the string resources

        <string name="menu_item_a">Start Activity A</string>
        <string name="menu_item_b">Start Activity B</string>
    

    Simply add this code to the base Activity in the code sample from inazaruk to see for yourself. Toggle between Activity A and Activity B a couple of times through the menu, and then try to close all Actitvities in the stack. It will not work.

    Now one would think the cause was the intent flag:

    Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
    

    However adding this flag to all intents in the code from inazaruk excludes this.

    If anyone can explain exactly what happens it would be great to hear.

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

Sidebar

Related Questions

In my app I've got certain buttons which use the following code: SystemSoundID beep;
When I close my app in a certain state, this code runs: void GameEndState::exit(){
My app uses a WebRequest at certain points to get pages from itself. This
When I run this code on my computer with the help of Google App
My app has several UIViewControllers in a stack (under a UINavigationController). In certain cases
What Is Working Fine I have 2 activities in my app. First activity calls
Context: I have a WPF App that uses certain unmanaged DLLs in the D:\WordAutomation\MyApp_Source\Executables\MyApp
I am writing an app that allows people to schedule things for certain times
The users of my app can configure the layout of certain files via a
In my asp.net mvc app I want to check if a certain url returns

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.