java - Thread in android not working as expected -
I'm following a guide that shows how to create a pong game. There is a part, where I want to make a thread, and the function that moves the ball.
This is the code I created:
package com. Ozadari.pingpong; Public class ping pong game thread {private ball gameball; Private PingPoint GameView; Public PingPongGame (Ball the Ball, Pingpong Wee Men V) {this.gameBall = theBall; This. GameView = mainView; } @ Override Public Wide Run (While {true} {this.gameBall.moveBall (); This.gameView.postInvalidate (); Try {PingPongGame.sleep (5); } Grip (Interrupted e) e.printStackTrace (); }}}} is called a thread and works, but it does not print anything. I tried to cancel the infinito loop and tried to run the loop 100 times. After waiting for some time for me, it prints on screen because it should be after 100 runs, but it does not print anything in the middle.
What is the problem? How can I fix this?
Unaware of the code you posted but anyway, you handler and run it once every time (Change the time you want):
handler handler = new handler (); Last Runnabel R = New Runnabal () {Public Zero Run () {// Handle Your Accessories Here Posted (this, 1000); }}; Handler Post Delayed (R, 1000);
You can also use the normal thread, and you can start the call at the end.
thread thread = new thread () {@Override Public Zero Moves () ({{true} {sleep (1000); handler.post (R);}} Grip (Interrupted e ) {E.printStackTrace ();}}}; thread.start ();
Comments
Post a Comment