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

The Archive Base Latest Questions

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

I have a launching Activity A1 which has a start button which starts a

  • 0

I have a launching Activity A1 which has a start button which starts a Service S1:

startButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                Log.i(TAG1, "Starting Update Service");
                startService(serviceIntentS1);
            }
        });

S1 depending on some condition starts Activity A2:

if (giveninteger>=2)
       {   
           Intent intentA2= new Intent(this, A2.class);
           // following line to avoid exception
           intentA2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //to avoid exception
           startActivity(intentA2);  

         }

A2 subscribes to S1 and from A2 user can see periodically updated data by the aid of S1. A2 has following code to stop S1 service:

public void onBackPressed() {
        try {
            Log.i(TAG2, "Killing Update Service");
            stopService(serviceIntentS1);

              } catch (NullPointerException e) {
            Log.i(TAG3, "Service was not running " + e.toString());
        }
        finish();
        System.exit(0);
        return;
    }  

My problem is that, if the update runs 10 times from A2, user has to press back button 10 times to exit Activity A2. That is instances of A2 are accumulated in Activity stack. I tried all flags during launch of A2 from S1, but without success. I want to exit the Activity A2 with just one back press, no matter how many times the update runs.

Any suggestions would help.

  • 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-27T01:47:05+00:00Added an answer on May 27, 2026 at 1:47 am

    What you need is a SingleInstance of A2 so that irrespective of the number times A2 is launched only one instance remains and you need to press back button only once.
    Define this attribute in the AndroidManifest file.

    <activity android:launchMode"singleInstance"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m new to android,I have an activity class which fetches Json string from url
I have an application where I am launching a new Activity, and need to
I have two activities with navigation menu which has items for launching Activity1 and
I have an app launching an executable which is in the same folder as
I have a ListView on main activity, which shows a Contact picture on the
I have an app that has a viewflipper to keep tabs in view at
I have a question regarding launching new activities. It boils down to this. I
I have trouble launching Glassfish v3 on Mac In Windows, after installation of Glassfish
i have a php file launching my exe. the exe does cout and the
When launching a process with CreateProcessW() , is it possible to have the process

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.