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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:31:36+00:00 2026-05-31T09:31:36+00:00

I have this what seems like a very tedious task of rescheduling a Timer

  • 0

I have this what seems like a very tedious task of rescheduling a Timer along with TimerTask to enable my service/ongoing process to execute at different times…i have tried searching many forums including this example which seems to have worked for this person but when i try the same code in my service, i get the following error:

03-04 14:21:41.204: E/AndroidRuntime(336): FATAL EXCEPTION: Timer-0

03-04 14:21:41.204: E/AndroidRuntime(336): java.lang.RuntimeException: Can’t create handler inside thread that has not called Looper.prepare()

Does anyone know what this error means, and what can be a possible solution? from what i researched online about this error: it usually happens when im trying to do UI changes, on a non-UI thread…in my case, all i do is send a notification and then call a reScheduleTimer function like in that example…

any input is appreciated…

EDIT:
here is the code where its blowing up:

    public void reScheduleTimer(long duration) {
    Log.v(TAG, "Inside reScheduleTimer");
    timer.cancel();
    timer = new Timer("profileSwitcherTimer", true); 
    timerTask = new MyTimerTask(); <----
    timer.schedule(timerTask, duration);
}

here is the MyTimerTask class:

public class MyTimerTask extends TimerTask{
private Handler updateUI = new Handler(){
        public void dispatchMessage(Message msg) {
            Toast.makeText(getApplicationContext(), "Timer Ran", Toast.LENGTH_LONG).show();
        }
}

public void run() {
    ....code that i want execute
    showNotification();
    reScheduleTimer(60000);
}

}

  • 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-31T09:31:37+00:00Added an answer on May 31, 2026 at 9:31 am

    You’re creating the Handler on a thread that does not have a message loop. As the Looper documentation says:

    Threads by default do not have a message loop associated with them;
    to create one, call prepare() in the thread that is to run the loop,
    and then loop() to have it process messages until the loop is stopped.

    One way to fix this would be to explicitly bind you Handler instance to a particular Looper, by using the Handler constructor that takes one. The easiest would be to just use the main looper for the application; you can get it thourgh the static Looper.getMainLooper() method. The drawback is that this will bind your handler to the UI thread, which by itself is not that bad, as long as you don’t do too long operations on it; otherwise your UI will become unresponsive.

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

Sidebar

Related Questions

I have an issue that seems like very flaky behavour, is this a problem
This seems like a simple problem: I have a WF4 activity that guides the
This seems like an incredibly dumb question to have to ask, but how do
This seems like a pretty softball question, but I always have a hard time
Why does Java not have a file copy method? This seems like such an
I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
Anybody have a slicker way to do this? Seems like it should be easier
This seems like a very basic question but I couldn't find any help on
This seems like a very simple question, but I've only found complicated answers. I've
This seems like a very simple question, but I'm getting lost, and need a

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.