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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:13:20+00:00 2026-06-04T15:13:20+00:00

To update a seekbar, I am using the following code: My problem is that

  • 0

To update a seekbar, I am using the following code:
My problem is that anytime the seekBar.setProgress() is call, other element on the UI become freezed, so I would like to have a different thread that update the seekBar in the main thread.

How to proceed ?

    private Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        try {
            int pos;
            switch (msg.what) {
            case SHOW_PROGRESS:
                pos = setProgress();
                if (!mDragging && mBoundService.isPlaying()) {
                    msg = obtainMessage(SHOW_PROGRESS);
                    sendMessageDelayed(msg, 100 - (pos % 1000));
                }
                break;
            }
        } catch (Exception e) {

        }
    }
};

private int setProgress() {
    if (mBoundService == null || mDragging) {
        return 0;
    }
    int position = mBoundService.getCurrentPosition();
    int duration = mBoundService.getDuration();
    if (sliderSeekBar != null) {
        if (duration > 0) {
            // use long to avoid overflow
            long pos = 1000L * position / duration;
            sliderSeekBar.setProgress((int) pos);
        }
    }

    if (sliderTimerStop != null)
        sliderTimerStop.setText(stringForTime(duration));
    if (sliderTimerStart != null)
        sliderTimerStart.setText(stringForTime(position));

    return position;
}
  • 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-04T15:13:22+00:00Added an answer on June 4, 2026 at 3:13 pm

    Activities have a runOnUiThread method that allows separate threads to update UI components. Your setProgress method would end up looking like:

    private int setProgress() {
    
        if (mBoundService == null || mDragging) {
            return 0;
        }
        final int position = mBoundService.getCurrentPosition();
        final int duration = mBoundService.getDuration();
    
        runOnUiThread(new Runnable(){
    
            @Override
            public void run(){
    
                if (sliderSeekBar != null) {
                    if (duration > 0) {
                        // use long to avoid overflow
                        long pos = 1000L * position / duration;
    
                        sliderSeekBar.setProgress((int) pos);
                    }
                }
    
                if (sliderTimerStop != null)
                    sliderTimerStop.setText(stringForTime(duration));
                if (sliderTimerStart != null)
                    sliderTimerStart.setText(stringForTime(position));
            }
        });
    
        return position;
    

    }

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

Sidebar

Related Questions

UPDATE: so i am using seekbar and Seekbar and hook up the listeners onCreate
I hope this is a simple problem. I have a seekbar that I want
UPDATE : The full site code is here - https://github.com/eWizardII/PeerInstruction I have the following
[Update]: my initial example doesn't reflect my problem. Updated the sample, hopfully it is
Update: This does work, I was being stupid :( i have the following extension
****Update:** using the Rank() over partition syntax available in MS SQL Server 2005 does
Update: Based on the answers I initially went the route of using IsInstanceOf() which
Update: This is, as I was told, no principle Python related problem, but seems
Update I want to have an expression (XPath, or Regex Expression, similar) that can
I have a ListView in which each item has a SeekBar. When I update

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.