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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:40:11+00:00 2026-06-06T07:40:11+00:00

I have a simple graphics application which draws some stuff on the screen. Before,

  • 0

I have a simple graphics application which draws some stuff on the screen. Before, I had no problem when I was calling invalidate() in onDraw() without a check. In my application onDraw() is called many times each second (which I came to know through Logs), but I don’t want to call it many times each second, as I want to update the screen after each second only. So I tried to compare previous and current seconds — if they are the same, I won’t call invalidate(); if the second changes, I will call invalidate(). Here is my code:

protected void onDraw(Canvas canvas) {         
    // Create date to check current second
    Date date = new Date();
    canvas.drawColor(Color.WHITE);

    drawArcs(canvas, mBigOval, mUseCenters[0], mPaints[0]); 

    //Get the current second 
    curSec = date.getSeconds();
    //compare if its same as lastSec which is updated in drawArcs() which i called before

    do {    
        Log.d("Graphics","curSec="+curSec+"  lastSec="+lastSec);
        curSec = date.getSeconds();
    } while(curSec == lastSec);

    Log.d("Graphics","Calling invalidate() and  count="+(++count));
    invalidate();
}  

With the above code, if my application gets launched at the 30th second then the log shows:

     06-25 10:25:52.257: D/Graphics(14711): curSec=30  lastSec=30

The above logs keep on repeating with no change in curSec and lastSec. Why is the second not updating even if I’m updating it every time the loop goes through.

  • 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-06T07:40:13+00:00Added an answer on June 6, 2026 at 7:40 am

    Your Date object was created and set to the current time when you instantiated it with:

    Date date = new Date();
    

    Every time you call date.getSeconds(), you’re just getting the seconds on that same Date object, whose time hasn’t changed.

    That said, your real issue is that you’re calling invalidate() from onDraw(), forcing another call to onDraw() (which forces another…). You don’t need to do that; onDraw() is already called whenever the View becomes invalid. If you’re trying to animate (at 1 fps?) you can use a Handler with postDelayed() or a SurfaceView and another thread.

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

Sidebar

Related Questions

I'have written a simple code, that gets accelerometer&orientation meter and display some graphics based
I have simple WinForms application where modifying Windows Registry. The problem is that in
I have this simple application in which a command like RECT 10 20 100
I am working on an application which draws a simple dot grid. I would
I have in mind one simple application, but I would like to add some
I have written a GUI application which after performing some analyses on a large
I have a small, simple C# application which updates an icon in the system
I have a google map inside my android application which have a simple hardcoded
I already made a simple android application, which I also have integrated Google Maps
I have simple SSIS package which reads data from flat file and insert into

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.