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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:12:06+00:00 2026-05-23T14:12:06+00:00

I am working on an application with several Activities, problem is that I want

  • 0

I am working on an application with several Activities, problem is that I want the user to be able to log out by pressing a button.

Suppose we have 4 Activity named A,B,C,D. Navigation of the activity like B->C->D.

On Activity D user have options for logout. When user click on the Logout button the he go to Activity A which is not called in the navigation. Now, user click on the back button then he got to previous activity like Activity D.

I already tried to launch the Activity with the two following flags:

Intent intent = new Intent(this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);        
startActivity(intent);

Can anyone 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-23T14:12:06+00:00Added an answer on May 23, 2026 at 2:12 pm

    Okay, I made myself a small project to somewhat simulate what you have. I’m going to leave out the imports in the code below. Also, read all the code and comments, I didn’t write them to have you skip over them. Let’s call the classes splash, login, page1, page2, and page3. In your splash class, before the onCreate() method, let’s put a few things.

    package com.test.jeets;
    
    public class splash extends Activity {
    
        //Add all of these right here!
        public static boolean loggedin = false;
        public static int sdk = new Integer(Build.VERSION.SDK).intValue();
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);
            //This is your splash screen, all the code goes here!
        }
    }
    

    Now that’s your splash screen! Done! For the login screen, we’ll want to make sure it can’t go back to the splash screen, and instead exit out of the app when back is pressed. That’s easy! Let’s just override the back button and use moveTaskToBack(true).

    package com.test.jeets;
    
    public class login extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.login);
    
            //This is the login page stuff. Nothing special needs done here.
        }
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event)  {
            if (splash.sdk < 5 && keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                onBackPressed();
            }
    
            return super.onKeyDown(keyCode, event);
        }
        //This will make the back button exit the app to the home screen.
        @Override
        public void onBackPressed() {
            moveTaskToBack(true);
            return;
        }
        //If the user leaves the app from the login screen while not logged in, they are returned to the splash screen.
        @Override
        public void onRestart() {
            super.onRestart();
            if(splash.loggedin == false){
            Intent i = new Intent(login.this, splash.class);
            startActivity(i);}
        }
    }
    

    Now, that’s done! Let’s go to your first page (the page you go to after you’re logged in) and add a line in the onCreate() method

    splash.loggedin = true;
    

    You might want to consider having a user back out of this page log them out as well. Not necessary, but certainly do-able.

    The last thing you’ll need to do is set that variable to false when a user logs out with the logout button. So in the code for the button, before the call to start the login activity again, just add splash.loggedin = false;. Now when the button is clicked, it will log the user out, set the variable to false, and take them to the login screen. Like I said, I tested this with a simple layout and real basic switch between activities and it worked fine for me.

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

Sidebar

Related Questions

I'm working on an Android application that has several Activities. In it I have
I am working on splitting out an existing, working application that I currently have
I have been working on a C# WinForms application that registers several hot keys
I'm working on an application that will gather data through HTTP from several places,
I am currently working on an application that uses a TableViewer in several places
I'm working on a desktop application that will produce several in-memory datasets as an
I am working on localization for a asp.net application that consists of several projects.
We have a scripting engine (running under Windows) that launches another application several thousand
I have a Websphere Portal application containing several portlets for which I'm currently working
We're designing an Android app that has several activities which are working in a

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.