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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:56:37+00:00 2026-06-07T17:56:37+00:00

Assume i have four classes.Each class is having a button to do screen switching

  • 0

Assume i have four classes.Each class is having a button to do screen switching from one page to another page,well its working fine.But now im trying to close all the activities by clicking the button from the last page.I have tried that too, but its just closing only the last page.How to achieve this concept?

Please find my code for reference

Xit_demoActivity.java

public class Xit_demoActivity extends Activity {
/** Called when the activity is first created. */

Button btn1; 

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    btn1 = (Button)findViewById(R.id.button_1);
    btn1.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
    Intent myIntent = new Intent(v.getContext(), Class1.class);
    startActivity(myIntent);
        }
    });

Class1.java

public class Class1 extends Activity 
{

Button btn1;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main1);

    btn1 = (Button)findViewById(R.id.button_2);
    btn1.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
    Intent myIntent = new Intent(v.getContext(), Class2.class);
    startActivity(myIntent);
        }
    });

Class2.java

public class Class2 extends Activity 
{

Button btn1;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main2);


    btn1 = (Button)findViewById(R.id.button_3);
    btn1.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
    Intent myIntent = new Intent(v.getContext(), Class3.class);
    startActivity(myIntent);
        }
    });

Class3.java

public class Class3 extends Activity 
{
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main3);

    Button next = (Button) findViewById(R.id.button_4);
    next.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) 
    {
        Intent intent = new Intent();
        setResult(RESULT_OK, intent);
        finish();
        }
    });

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.and.roidu.xit"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".Xit_demoActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity><activity android:name=".Class1"></activity>

    <activity
        android:name=".Class1"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN1" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity><activity android:name=".Class2"></activity>



    <activity
        android:name=".Class2"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN2" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity><activity android:name=".Class3"></activity>

    <activity
        android:name=".Class3"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN3" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


 </application>

</manifest>

Thanks for your time!..

  • 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-07T17:56:38+00:00Added an answer on June 7, 2026 at 5:56 pm

    Simply try this. Consider your Class3.java is your last Activitiy And, in Button of next use below code –

    Intent intent = new Intent(currentActivity.this, XitActivity.class); // instead of XitActivity use your first activity
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("EXIT", true);
    startActivity(intent);
    

    And, in your Xit_demoActivity‘s onCreate() use below code –

    if (getIntent().getBooleanExtra("EXIT", false)) {
        finish();
    }
    

    Hope this will helps you to exit you from all activities.

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

Sidebar

Related Questions

I have a dilemma. Let's assume(for simplicity's sake) I have four tables, with different
Assume I have a C# class like this: [XmlRoot(floors)] public class FloorCollection { [XmlElement(floor)]
Assume I have this domain object... public class SpansMultipleTables { public int CommonID {get;
Assume we have a single Windows form with a button called SimpleButton1. The following
Let's assume that I have following models: class ScoutBook(models.Model): troop = models.ForeignKey('Dictionary', limit_choices_to={'type' :
I have these four table assume that ring table consist of five fields(jewelry_id,ring_id,image,type,brand_id) Note
Assume I have the following: <input type=text> <div id=listofstuff> <div class=anitem> <span class=item name>Dog</span>
Assume, I have two firms Firm 1 and Firm 2 in firm table. Each
Assume I have the following string: Hellotoevryone<img height=115 width=150 alt= src=/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg />Iamsogladtoseeall. This
Assume I have access to a SMB server at IP 1.2.3.4, how can I

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.