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

  • Home
  • SEARCH
  • 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 684279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:47:57+00:00 2026-05-14T01:47:57+00:00

So I have a very simple android activity that starts a timer when you

  • 0

So I have a very simple android activity that starts a timer when you hit a button.

Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
doStuff();
}
}, 15 * 60 * 1000);

So this worked reasonably well for me when I was testing but as it turns out when the screen becomes inactive so does the timer. I was a bit surprised by this. I understand you need to create a service to have anything running in the background but I hadn’t realized this is required for an activity in the foreground when the phone has inactivated the screen due to lack of activity. What confuses me is I think this worked as I expected originally and just in the last few weeks or so has the timer been affected by the phone saving power. I could be wrong though..

So basically my questions are: am I seeing expected behavior? Do I need to create all timers as services or somehow disallow powersaving?

thanks for any advice,
Patrick

  • 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-14T01:47:57+00:00Added an answer on May 14, 2026 at 1:47 am

    I was a bit surprised by this.

    When the screen goes off, the CPU shuts down shortly thereafter. Your user of Timer has nothing to do with it, as that’s a Java thing, not an Android thing.

    What confuses me is I think this
    worked as I expected originally and
    just in the last few weeks or so has
    the timer been affected by the phone
    saving power.

    I highly doubt that.

    am I seeing expected behavior?

    Yes.

    Do I need to create all timers as
    services or somehow disallow
    powersaving?

    If you have an activity that must keep the screen and device on, use:

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    

    However, this should be for something like a video player.

    If you are trying to do something more like a Windows scheduled task or Linux cron job, you will want to use AlarmManager and an IntentService, perhaps a WakefulIntentService.

    There are other possibilities as well, but I don’t know what you’re trying to build.

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

Sidebar

Related Questions

I have a very simple app for Android that displays a Google Maps view
I have a very simple game that consists of only one activity, and I
I have a very simple Activity with the following layout... <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent
I have a very simple dialog defined as: import android.app.AlertDialog; import android.content.Context; import android.view.LayoutInflater;
I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();
Before I delve into it, I'm very new to Android and I have just
I have developed a very simple Android native app to launch my HTML5 webapp.
Hey guys i have a ListActivity... a very simple at that... and it keeps
In a very short and simple LVL callback function, I have: public void applicationError(ApplicationErrorCode
I have an Android widget that has a configure activity. I also have an

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.