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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:40:14+00:00 2026-05-23T16:40:14+00:00

Say I want to draw a line, then wait five seconds, then draw another

  • 0

Say I want to draw a line, then wait five seconds, then draw another line. I have a method like this:

    public void onDraw(Canvas canvas) {
        int w = canvas.getWidth();
        int h = canvas.getHeight();
        canvas.drawLine(w/2, 0, w/2, h-1, paint);
        // PAUSE FIVE SECONDS
        canvas.drawLine(0, h/2, w-1, h/2, paint);
    }

How do I pause?

  • 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-23T16:40:15+00:00Added an answer on May 23, 2026 at 4:40 pm

    Don’t wait in onDraw method it’s called in the UI thread and you’ll block it. Use flags to handle which line will be drawn

    boolean shouldDrawSecondLine = false;
    
    public void setDrawSecondLine(boolean flag) {
        shouldDrawSecondLine = flag;
    }
    
    public void onDraw(Canvas canvas) {
        int w = canvas.getWidth();
        int h = canvas.getHeight();
        canvas.drawLine(w/2, 0, w/2, h-1, paint);
        if (shouldDrawSecondLine) {
            canvas.drawLine(0, h/2, w-1, h/2, paint);
        }
    }
    

    Than use it in your code like this

    final View view;
    // initialize the instance to your view
    // when it's drawn the second line will not be drawn
    
    // start async task to wait for 5 second that update the view
    AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
            }
            return null;
        }
    
        @Override
        protected void onPostExecute(Void result) {
            view.setDrawSecondLine(true);
            view.invalidate();
            // invalidate cause your view to be redrawn it should be called in the UI thread        
        }
    };
    task.execute((Void[])null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say we have a 400x800 canvas and I want to draw a line
Let's say I want to draw a simple quad like this: glBegin(GL_QUADS); glVertex2f(-1.0,-1.0); glVertex2f(1.0,-1.0);
Say I want to write a function like this: int get_some_int(string index) { ...perform
Say I want to have a method that takes any kind of number, is
Let's say I have a shape like this: After all the jokes of me
Let say that i have id of another Xlib window and i want to
Say if I have a Java Graphics object, and I want to draw a
This is mostly a theoretical question. Let's say I want to draw a triangle
I want to draw a line in matlab. My scenario is like x=[-400:400] and
Say I want to draw a Ball in the scene and here are two

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.