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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:18:26+00:00 2026-05-26T05:18:26+00:00

Inside my Android code, I’m responding to a button press by calling Timer.schedule(myTask,0,1000), which

  • 0

Inside my Android code, I’m responding to a button press by calling Timer.schedule(myTask,0,1000), which calls myTimerTask::run(), which is something like this:

nested within my Activity:

class mytimerTask extends TimerTask {
    @Override
    public void run() {
        //update my progress bar
        //if progress bar is full, i want to call a function that is in my activity
    }
}

Can I straight up reference one of my Activity methods from TimerTask? It seems to crash the app when I try it.

Would it be better for me to handle my ProgressBar and eventual execution of code from a Runnable instead of a Timer/TimerTask?

  • 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-26T05:18:26+00:00Added an answer on May 26, 2026 at 5:18 am

    You need to yor code as follow. To know reason check following thread
    What is the Android UiThread (UI thread) or http://developer.android.com/resources/articles/painless-threading.html

       Timer t;
       Handler handler = new Handler();
    
    
    t = new Timer();
    Class MyTimerTask extends TimerTask{
        public void run() {
                handler.post(new Runnable() {
                        public void run() {
                            //update my progress bar
        //if progress bar is full, i want to call a function that is in my activity
    
                        }
               });
        }
    
        t.schedule(timeTask, 0, 1000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inside my code I'm generating hashes of URLs, (which are practically of unbounded length).
I want to display toast message inside timer and I used the following code
I have a button inside an updatepanel. I have a PopupControlExtender linked to the
I'm trying to use a blowfish cipher inside an Android application. It appears that
I have the following code running on my Android device. It works great and
Calling a .net SOAP1.1 web service from android using ksoap2 lib I met a
Can I access android MediaProvider (Images & Videos) databases directly from my code rather
I am trying to determine how to structure the code of a simple android
I'm using the following code which only zooms the loadData. How is it possible
I'm new to android, bear it with me. I've a TimerTask for which I

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.