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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:09:37+00:00 2026-05-25T17:09:37+00:00

In my app i have 3 activities. From 1st activity it goes to 2nd

  • 0

In my app i have 3 activities.

From 1st activity it goes to 2nd and from 2nd it goes to 3rd. From 3rd it is coming to 1st again. and if I press back key from the 1st then it should go to home screen (App will stop).
If I press back key of 1st its goes to 2nd activity again and if I press 2nd’s back key, then it goes to the 1st . Then if I press back key of 1st then app stops.

What I want , when I am in 3rd activity and press the back button then it should go to 1st and simultaneously finish the 2nd activity.

How can I do that?

  • 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-25T17:09:38+00:00Added an answer on May 25, 2026 at 5:09 pm

    just finish the second activity when you open third activity

    suppose in second activity on some button click you are opening third activity using start activity;

    startActivity(intent);
    finish();//this will finish second activity and open third activity so when you press back from third activity it will open first activity.
    

    if you want depended on some condition then on activity

    setResult(123);
    

    something code like this

    now when override onActivityResult in second activity

    @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            if(resultCode==123){
                //finish
            }
        }
    

    also make sure one thing you need to use startActivityForResult(intent, requestCode); for result in second activity to start third activity.

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    public class Activity2 extends Activity{
    
        Button button;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main1);
    
            button.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    startActivityForResult(new Intent(new Intent(Activity2.this,Activity3.class)), 12);
                }
            });
        }
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    
            if(resultCode==123 && requestCode==12){
                finish();
            }
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
    
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    public class Activity3 extends Activity{
    
        Button button;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main1);
            button.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    setResult(123);
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our app, we have Activities A,B,C,D, and E. The user usually goes from
I have a native android app in which there are two activities, 1st activity
I have an app that contains several activities...so lets say user is navigating activity
In my app, I have different activities with listviews. The datas come from a
In my Android App I have a main activity and some other activities. The
I have 2 activities in my app and I would like activity X to
I have four activities, A, B, C and D. app starts with activity A,
I have 3 activities. 1st activity has a 'go right' image button. (to move
Example : I have 3 Activities, A,B, and C. from Activity A I open
I have an app which has a main activity that calls other activities on

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.