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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:50:59+00:00 2026-05-30T18:50:59+00:00

I dont know whats wrong going on… I am not able to start a

  • 0

I dont know whats wrong going on… I am not able to start a timer in my service. Following the code

public class BkgService extends Service{

private Timer ServUpdTimer = new Timer();
private static  long TMR_INTERVAL = 10*60*1000;

public void onCreate() {
    super.onCreate();
    StartServUpdateTask();
    }

private void StartServUpdateTask() {

        if(ServUpdTimer != null)
            ServUpdTimer.cancel();


        ServUpdTimer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
            }
        }, 0, TMR_INTERVAL);
    }
}

But when I reach to the line ServUpdTimer.scheduleAtFixedRate() I am getting the following exception

03-03 23:32:14.851: E/AndroidRuntime(6083):
java.lang.RuntimeException: Unable to start service
mt.android.app.BkgService@40544838 with Intent {
cmp=mt.android.app/.BkgService }: java.lang.IllegalStateException:
Timer was canceled

I would be very grateful if someone can throw some light on this…

  • 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-30T18:51:00+00:00Added an answer on May 30, 2026 at 6:51 pm

    From the Javadoc for Timer.cancel():

    Once a timer has been terminated, its execution thread terminates gracefully, and no more tasks may be scheduled on it.

    From the Javadoc for Timer.scheduleAtFixedRate():

    Throws: IllegalStateException – if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated.

    The Timer is cancelled immediately: you need to create a new instance:

    private void StartServUpdateTask() {
    
        if(ServUpdTimer != null)
        {
            ServUpdTimer.cancel();
        }
        ServUpdTimer = new Timer();
    
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code I dont know whats wrong with it. <?php //Logout code
I realy dont know what the problem is with VS2010. I created a class,
I don't know what is going but my jquery validate plugin(1.5.5) is not working
i'm not sure what is going wrong, but I created a Date field, and
I don't know what's going wrong here. The crash happens when switching back and
I don't know whats going on... I have this: console.log(n=+n): console.log(longest.length=+longest.length); console.log(longest.length/n=+longest.length/n); if (
I don't know what's make wrong, my map can load, but the image on
I don't know what I'm doing wrong, but sorl-thumb just uploads the image but
I dont know what happend but I cant register any dlls anymore. It seems
its kind of silly question. but i dont know what mistake i am making.

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.