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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:27:50+00:00 2026-05-23T11:27:50+00:00

My android application requires a password to be entered in the first activity. I

  • 0

My android application requires a password to be entered in the first activity. I want to be able to automatically send the application back to the password entry screen after the application has been idle for a fixed amount of time.

The application has multiple activities, but I would like the timeout to be global for all activities. So, it wouldn’t be sufficient to create a timer thread in the onPause() method of an Activity.

I’m not sure what the best definition for the application being idle is, but no activities being active would be sufficient.

  • 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-23T11:27:50+00:00Added an answer on May 23, 2026 at 11:27 am

    I know another answer is accepted already, but I came across this working on a similar problem and think I’m going to try an alternate much simpler approach that I figured I may as well document if anyone else wants to try to go down the same path.enter code here

    The general idea is just to track the system clock time in a SharedPreference whenever any Activity pauses – sounds simple enough, but alas, there’s a security hole if that’s all you use, since that clock resets on reboot. To work around that:

    • Have an Application subclass or shared static singleton class with a global unlocked-since-boot state (initially false). This value should live as long as your Application’s process.
    • Save the system time (realtime since boot) in every relevant Activity‘s onPause into a SharedPreference if the current app state is unlocked.
    • If the appwide unlocked-since-boot state is false (clean app start – either the app or the phone restarted), show the lock screen. Otherwise, check the SharedPreference‘s value at the lockable activity’s onResume; if it’s nonexistent or greater than the SharedPreference value + the timeout interval, also show the lock screen.
    • When the app is unlocked, set the appwide unlocked-since-boot state to true.

    Besides the timeout, this approach will also automatically lock your app if your app is killed and restarts or if your phone restarts, but I don’t think that’s an especially bad problem for most apps. It’s a little over-safe and may lock unecessarily on users who task switch a lot, but I think it’s a worthwhile tradeoff for reduced code and complexity by a total removal of any background process / wakelock concerns (no services, alarms, or receivers necessary).

    To work around process-killing locking the app regardless of time, instead of sharing an appwide singleton for unlocked-since-boot, you could use a SharedPreference and register a listener for the system boot broadcast intent to set that Preference to false. That re-adds some of the complexity of the initial solution with the benefit being a little more convenience in the case that the app’s process is killed while backgrounded within the timeout interval, although for most apps it’s probably overkill.

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

Sidebar

Related Questions

I'm writing an Android application that I want to be able to send requests
I'm planning to implement an Android application that requires a login screen. If the
I want to create an android application which requires Kannada language,the regional languauge of
I have a Android application that requires a splash screen. I have a simple
I developed one simple android application targeting the Mobiles with android 2.0 OS.I want
In a Android application I want to use Scanner class to read a list
I am trying to build an android application. The application requires android 2.2 and
I am building an Android application that requires OAuth. I have all the OAuth
I am working on an android application that requires multiple views which will overlap
I'm new to Android development and working on an Android application that requires the

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.