Note that there are some explanatory texts on larger screens.

plurals
  1. POHow continue updating screen without flooding onTouchEvent ? (android SurfaceView)
    text
    copied!<p>When you have a surfaceView class, used for animation/game/... you have the onTouchEvent() method and the drawing/screen-refreshing method in that same class. Now I want to just sleep the onTouchEvent method, so it doesn't get called +-80 times a second and flooding the cpu (and therefor causing lag). The problem is that if I sleep this class, it also stops drawing/updating/refreshing. What could be a good solution for this?</p> <p><strong>Edit</strong><br> @tanner, that's indeed what i'm trying, to stop onTouchEvent() to be called too frequently. my attempt: </p> <pre><code>@Override public boolean onTouchEvent(MotionEvent event) { Log.d("firstTest",Integer.toString(event.getAction())); //shows up if (!sleeper.CurrentlySleeping) { Log.d("2ndTest",Integer.toString(event.getAction())); //not showing up ~~ some calculations and stuff ~~ </code></pre> <p>. </p> <pre><code>public class TouchSleeper extends Thread { // If Thread is sleeping or not. public static Boolean CurrentlySleeping; public TouchSleeper() { CurrentlySleeping = false; this.setPriority(MIN_PRIORITY); } @Override public void run() { try { while (true) { CurrentlySleeping = true; TouchSleeper.sleep(50); CurrentlySleeping = false; } ~end~ </code></pre> <p>First a piece of code from my SurfaceView class. Second piece of a class/thread, wich keeps changing a boolean value. Note how my first Log.d does return something, and the second one doesn't. This tells me that CurrentlySleeping is never false ? I still have not figured things out... ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload