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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:26:27+00:00 2026-05-25T22:26:27+00:00

I’m using Android 2.2. I have an application which logouts (causing the application to

  • 0

I’m using Android 2.2. I have an application which logouts (causing the application to return to the login page) after a certain period of inactivity. I am using Intent.FLAG_ACTIVITY_CLEAR_TOP for my Intent. However, I notice that when my application is on background and is inactive for a certain period of time, the login page suddenly pops-up and my application goes to foreground. I am expecting that the login page will remain to background. This does not happen when I am not using any flag for my intent. If I’m not using any flag for my Intent, the login page is quietly started on the background. But without using Intent.FLAG_ACTIVITY_CLEAR_TOP, I won’t be able to clear my history stack.

Why is this happening? How can I launch an activity on background quietly?

Below is a snippet of my code:

@Override //Inside a class extending AsyncTask
protected void onPostExecute(String result)
{
    ((GlobalApplication)getApplicationContext()).setIsLogin(false); //user is not logged in anymore
    Intent intent = new Intent(this, LoginActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
}

Below is a snippet the code I made from Lars’ suggestion:

@Override //Inside a class extending AsyncTask
protected void onPostExecute(String result)
{
    ((GlobalApplication)getApplicationContext()).setIsLogin(false); //user is not logged in anymore
    Intent intent = new Intent(this, LoginActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    if(((GlobalApplication)getApplicationContext()).isOnBackground())
        ((GlobalApplication)getApplicationContext()).setPendingIntent(intent);
    else
        startActivity(intent);
}

@Override //overrides android.app.Activity. inside the current Activity
protected void onResume()
{
    super.onResume();
    Intent pendingIntent = ((GlobalApplication)getApplicationContext()).getPendingIntent();
    if(pendingIntent != null)
        startActivity(pendingIntent);
}
  • 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-25T22:26:28+00:00Added an answer on May 25, 2026 at 10:26 pm

    Have you tried checking if you are still logged in in the onResume part of your activities instead of calling your LoginActivity when a timer goes off (which is what I’m assuming you are doing)?

    Edit: For clarification, you are logging the user out after a predefined period of time (or when an event occurs). At this point you start an AsyncTask which creates an intent for your loginActivity, adds a flag to it and starts it. And your problem is that you don’t want the loginActivity to come to the foreground unless the user has the application open. Is that accurate?

    Because if so I would recommend using the onResume methods like I mentioned above. These are called whenever an activity comes (back) to the foreground. For showing the login screen even when the user doesn’t change activities you could try sending a broadcast and listening for it in your activities.

    EDIT: Code snippet from my comment (Now correctly formatted):

    @Override    
         protected void onResume() {   
             super.onResume();   
             if (!getLoggedIn())   
             {  
                  startActivity(new Intent(this, LoginActivity.class));   
                  finish();   
             }   
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm making a simple page using Google Maps API 3. My first. One marker
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

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.