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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:18:54+00:00 2026-06-06T19:18:54+00:00

This function resides in a Service when called by an activity it should will

  • 0

This function resides in a Service when called by an activity it should will generate a random number and add that to a ArrayList. Everytime a new item is added it will try to update UI via update which calls runOnUiThread to use these number to plot a line graph and then wait 1 second. I want the update to happen every second. Is there a way to force activity to clear execute its message queue? As of right now it waits until this thread finish executing before it updates. Should I implement this in AsyncTask instead?

public void pollDP(int numPt){
    final Random gen = new Random();
    final int numPtF = numPt;
    serverLoadList = new ArrayList<Integer>();

        new Thread(new Runnable(){
            @Override
            public void run(){
                for(int i = 0; i < numPtF; i++){
                    serverLoadList.add(gen.nextInt());
                    update();
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
            }

        }).run();
    }
}
  • 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-06T19:18:55+00:00Added an answer on June 6, 2026 at 7:18 pm

    The solution is in the comment on my question by Martze. I am making this the solution for my problem.

    try using Thread.start() instead of Thread.run(). If you use run(), the Runnable is not launched in a new Thread. If this didn’t help, post some code of the update() method. Am i right by guessing you are calling pollDP from UI-Thread? – Martze

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

Sidebar

Related Questions

This function works as it should, window.setInterval(function(){ var active = $('#frontpageControls a.active'); var next
I have the following code that resides in my .js file //This is the
I have a function that resides in a class in an application my objective
I'd like to call a function that resides in a 3rd-party .exe and obtain
I'm trying to create a doctest with mock of function that resides in a
This function works fine: std::string get_str() { return std::get<0>( make_tuple(std::string(hi)) ); } But if
This function is in a Class file in App_Code folder Public Shared Function CRUD(ByVal
This function only works once, when I click an anchor element again, nothign happens.
This function gives error: function RefreshGrid(){ window.location.href=Form_ElameMamoreBazdid.aspx; }
This function sets up the Magento Grid to display a list of filenames with

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.