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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:24:15+00:00 2026-05-31T22:24:15+00:00

I’m simply not getting this to work. I saw that this network isn’t for

  • 0

I’m simply not getting this to work.
I saw that this network isn’t for just simple code correcting posts.
But I think this is in the interest of others to because there werent any good tutorials.

So I’m calling a canvas and I can draw on it in the ondraw() method but when I try to draw out of the game loop it draws nothing. I even don’t get an error messasge.

App :

public class App extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        draw d = new draw(this);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);


        setContentView(d);

    }
    public void end()
    {
        App.this.finish();
    }
}

draw.java :

public class draw extends View {
    Canvas ca;
    View v;
    Paint paint;

    int width;
    int height;

    static final int MAX_GAME_SPEED=33;
    static int fps; 
    boolean running=true;



    int pw=0,ph=0;





    public draw(Context context) {
            super(context);
        }  

            @Override
        protected void onDraw(Canvas c){
        super.onDraw(c);
        paint = new Paint(); //Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);


        //get screen size
        WindowManager wm = (WindowManager) this.getContext().getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();


        width = display.getWidth();  // deprecated
        height = display.getHeight();  // deprecated







            // make the entire canvas white
            paint.setColor(Color.WHITE);
            c.drawPaint(paint);


            ca = c;
            paint.setColor(Color.BLACK);
            c.drawRect(Math.round(width/3),Math.round(height/3),Math.round((width/3)*2),Math.round((height/3)*2), paint); //position width, position height,width,height


            paint.setStyle(Paint.Style.FILL);
            paint.setAntiAlias(true);
            paint.setTextSize(30);
            paint.setColor(Color.GREEN);
            c.drawText(String.valueOf(width)+"x"+String.valueOf(height)+","+Math.round(width/3)+"x"+Math.round(height/3), 30, 200, paint);
            paint.setColor(Color.GREEN);
            c.drawText(String.valueOf(width)+"x"+String.valueOf(height)+","+Math.round(width/3)+"x"+Math.round(height/3), 30, 200, paint);


            Thread myThread = new Thread(new UpdateThread());
            myThread.start();

    }
            public void paint(Canvas c)
            {

                paint.setColor(Color.GREEN);
                c.drawRect(20, 5, 50, 100, paint);

                pw++;
                ph++;



                /*if (pw >= width || ph >= height)
                {
                    pw=0;
                    ph=0;
                }
                */

            }
            public Handler updateHandler = new Handler(){
                /** Gets called on every message that is received */
                // @Override
                public void handleMessage(Message msg) {

                   paint(ca);


                    super.handleMessage(msg);
                }
            };



            public class UpdateThread implements Runnable {

                @Override
                public void run() {
                     while(true){
                         draw.this.updateHandler.sendEmptyMessage(0);

                    }
                }

            }

    }
  • 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-31T22:24:16+00:00Added an answer on May 31, 2026 at 10:24 pm

    Firstly:
    You are sending update messages too often. I belive you are overloading your message queue with that.

    Secondly:
    You are using canvas instance saved at onDraw method. I think this is not right.
    Instead, you can change your UpdateThread.run() method to

    @Override
    public void run() {
        while(true){
            draw.this.postInvalidate();
        }
    }
    

    This will send message to invalidate and repaint your View and thus call to your View.onDraw(Canvas) method with proper Canvas.

    Also:
    If you want to render your View as much as possible you must to implement next sequence:

    static final int MSG_REDRAW = 1;
    
    Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case MSG_REDRAW:
                // This method invoked on UI thread - ok.
                draw.this.invalidate();
                sendEmptyMessage(MSG_REDRAW);
                break;
    
            default:
                super.handleMessage(msg);
                break;
            }
        }
    }
    

    and instead of scheduling thread (UpdateThread) you need to just send first MSG_REDRAW message.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.