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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:17:37+00:00 2026-06-03T19:17:37+00:00

I have a timer that I want to start an AsyncTask when the countdown

  • 0

I have a timer that I want to start an AsyncTask when the countdown is done. If I put the execution of it in a handler it loops it and starts it many times. And if I dont put it in a Handler I get the following crash:
can’t create handler inside thread that has not called looper.prepare()

timer.schedule(new ListUpdate(), helper.nextListUpdate.get(0));

class ListUpdate extends TimerTask {
    private Handler mHandler = new Handler(Looper.getMainLooper());
    public void run() {
        mHandler.post(new Runnable() {
            public void run() {
                AsyncTask<Integer, Void, Boolean> task = new updateList();
                task.execute();
            }
        });
    }
}

Any suggestions of how I can solve 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-06-03T19:17:40+00:00Added an answer on June 3, 2026 at 7:17 pm

    By adding a handler outside of the TimerTask which I call from the TimerTask I could make it work!

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            RelativeLayout rl_header = (RelativeLayout)findViewById(R.id.rl_header);
            Desktop desktop = helper.getDesktop();
            try {
                desktop.inflate(ll, rl_header, banners, DesktopApp.this);
                Collections.sort(helper.nextListUpdate);
                helper.nextListUpdate.remove(0);
                timer = new Timer();
                if (helper.nextListUpdate.size() > 0) timer.schedule(new ListUpdate(), helper.nextListUpdate.get(0));
            } catch (Exception e) {
                e.printStackTrace();
            }
         }
    
    };
    
    class ListUpdate extends TimerTask {
        public void run() {
            DesktopApp.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    handler.sendEmptyMessage(0);
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have divs that I want to display at specific times throughout the day.
Say I have a function foo that I want to call n times. In
I have a function a time consuming operation that is done I want to
I have a function in R that I call multiple times. I want to
I have a path + filename that contains [] several times. What i want
I have a timer that needs to not process its elapsed event handler at
If we have a timer that starts from lets say CURRENT_TIMESTAMP - 1 Hour
I have created a javascript timer that starts at 40 and counts down by
I have a timer in my class that is I only ever want one
I have a timer and I want to put timer callbacks into separate functions,

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.