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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:55:35+00:00 2026-06-18T12:55:35+00:00

I am working on a Testing Project for me , just so I could

  • 0

I am working on a Testing Project for me , just so I could learn more , so now I need to update the text of a TextView constantly every 250 milliseconds through a for(;;) loop , it happens after a Button click … My problem is that whenever I press that button my app freezes (Yes my button is totally working , verified through previous testings) , I am using a handler to the Main thread doesn’t get affected while the Runnable is up … Here is my code of the Button and Handler …

final Handler handler = new Handler();
        B3.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {

                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        for(;;){
                            String a = Shells.sendSingleCommand("free");//Here I send a command "free" and it returns its output 
                            text.setText(a);//text is my TextView which is used through my experimentations ... 
                            synchronized(this){
                                try{
                                    wait(250);
                                }catch(Exception e){

                                }
                        }

                        }
                    }
                });
                }

        });

If you need anymore info ask please 🙂

  • 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-18T12:55:36+00:00Added an answer on June 18, 2026 at 12:55 pm

    use handler.postDelayed for updating textview constantly every 250 milliseconds instead of using for loop to avoid freeze current Activity as :

    Handler handler=new Handler();
    B3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                      handler.post(runnable);  
                    }
    
            });
    Runnable runnable=new Runnable(){  
      @Override  
        public void run() {  
           String a = Shells.sendSingleCommand("free");
           text.setText(a);
           handler.postDelayed(runnable, 250);  
         }  
     }; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started working on one project where I need to compress and
I am working on a sample project for testing KIF framework and Zapp. The
I'm working on my first project in which I'm utilizing PHPUnit for unit testing.
I am working with Silverlight Unit Testing i need to test a function which
I'm working on a project where I need to convert a few thousand documents
I made a test project just testing http request and response behavior, There is
Have been trying to get integration testing working with my seam project and the
I just start working on a project which I have to upgrade and upload
I'm working on a project that allows users to interact via SMS text messages.
I'm using junit and EasyMock to do unit testing on a project I'm working

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.