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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:44:06+00:00 2026-06-06T07:44:06+00:00

I havean Activity_A which has a Log-out option. On clicking that I call the

  • 0

I havean Activity_A which has a Log-out option. On clicking that I call the Log-in Activity. So when i Click device back button when i am on Login-in Activity it takes me back to the Activity_A where i have the log-out option. what i wanted is, when i click device back button when i am on log-in Activity it must take me to the device home screen. something like “close application” or “clear activity stack”.

I tried this:

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

but it didn’t work, i also tried using finish() int the above code, then it takes me to the Activity i called before Activity_A (as expected).

I searched for my case, and could not find a perfect solution, can someone please help me achieve what i wanted?

and i have an idea of overriding device back button onClick in my login Activity so that it shows the home screen of the device and clears all the activity stack….is it possible? if yes, is it safe?

This is what i have done in LoginActivity, which works just like i wanted

public void onBackPressed() {
    // TODO Auto-generated method stub
    super.onBackPressed();

    Intent startMain = new Intent(Intent.ACTION_MAIN);
    startMain.addCategory(Intent.CATEGORY_HOME);
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(startMain);
}

But is there any other way to achieve this without overriding onBackPressed()??

  • 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-06T07:44:08+00:00Added an answer on June 6, 2026 at 7:44 am

    You need to override the back button event and perform all the desired operation there.

    @Override
    
        public void onBackPressed() {
           //do whatever you desire
           return;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys I have an activity which has a home button, when the button is
I have an Activity class which has an attribute that references an AsyncTask instance
Here's the scenario I have an activity(A) which has a button and textview. I
I have a class that is supposed to call another activity depending on which
Good day. I have an app that has one main activity which holds 3
I have an activity which has count buttons plus and minus such that it
I have an Activity A which has a "down" button (see image above). When
I have an activity which has an EditText and a Button . The data
I have an Activity which has an 'OK' button. And I have an 'Edit'
I have an activity with a spinner which loads a simpleCursorAdaptor. I call another

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.