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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:11:39+00:00 2026-06-17T16:11:39+00:00

I have two activities A and B. B is a transparent pass through activity,

  • 0

I have two activities A and B. B is a transparent pass through activity, and A is seen. I want to kill B by pressing a button A.

Here’s what I’ve tried so far:

B obj=new B();
obj.finish();

I created an object of B and tried to kill it. That didn’t work.

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtra("keep", true);
                startActivity(intent);

What this code is supposed to do is clear the top most activity, which is B and call B again, except this time I’m passing a value such that B kills itself after a few seconds.

This only piled up more instances of the activity for some reason. Or at least I think that’s what happened because the screen became pixelated due to many transparent activities.

Here’s my manifest:

<activity
        android:name="com.xxx.xxx.B"
        android:excludeFromRecents="true"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"
        android:clearTaskOnLaunch="true" >
    </activity>

What do I have to do so that, when I hit a button once the activity is displayed and the second time kills it? The creation part is obviously taken care of. My activity B pops up, I want to kill it now that B is on top.

EDIT

I tried this with a checkBox, here’s the code:

enable.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            finishActivity(0);
            Intent intent = new Intent(A.this, B.class);
            if (enable.isChecked()) {
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtra("keep", true);
                intent.putExtra("value", 10);
                startActivityForResult(intent, 0);
            }
            else
            {
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtra("keep", false);
                startActivityForResult(intent, 0);
            }
        }
    });

When enable is checked the activity is called, which works fine. But they keep piling on. It’s not like this A->B->A->B when I check and uncheck the checkBox. It’s A->B->BB->BBB

  • 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-17T16:11:40+00:00Added an answer on June 17, 2026 at 4:11 pm

    You could try to directly kill an activity by calling a static method in that activity:

    Activity A should have a variable

     static ActivityA activityA;
    

    In onCreate state:

     activityA = this;
    

    and add this method:

    public static ActivityA getInstance(){
       return   activityA;
     }
    

    In activity B, call the function getInstance()

    ActivityA.getInstance().finish();     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two activities, Activity A and Activity B. I pass objects from Activity
I have two activities, Activity A has a button Load image which should let
I have two activities. In first I come to the second activity from first
This is my situation. I have two activities: ONE and TWO. In TWO activity
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, one is main and I have another activity called Test
I have two activities, say Activity A and Activity B . Activity A is
I have two activities. The first activity display list of the users with short
I have two activities or screens. The second activity has an AlertDialogBox with radiobuttons

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.