Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here I assume you mean SurfaceView, where you are using a background thread to draw to a surface and your are using SurfaceHolder.CallBack(). This is not a complete answer, however, this problem also has plagued me for a while. In my late night troubleshooting I managed to put together a workaround which may be a little more elegant than yours. The result being that nothing is drawn until the surfacechanged has settled to it's last state, so the user is unaware of what is happening.</p> <p>In your surfacechanged you'll notice that your height or width isn't changing to the correct value, in otherwords the result surface if drawn to is MalFormed. What you need is a reference value to what your height and width should be, you can get that by placing the following code before you SetContentView() in your main activity:</p> <pre><code>WindowManager w = getWindowManager(); Display d = w.getDefaultDisplay(); int Meausredwidth = d.getWidth(); int Measuredheight = d.getHeight(); </code></pre> <p>Now from your measured height and width, work out how much you are assigning to the surfaceView, and pass those values to your SurfaceView as global variables. And make sure you are calling the above code in onconfigurationchanged() in your main activity so those values get recalculated each time. Now on your SurfaceView which should somehow implement SurfaceHolder.Callback, Change your surfacechanged to look like this:</p> <pre><code>@Override public void surfaceChanged(SurfaceHolder mholder, int format, int width, int height) { if (width != mWidth) { MalFormed = true; thread.setRunning(false); count++; } else if (width == mWidth) { if (MalFormed) { MalFormed = false; Log.d("ROTATE", "ReDraw"); thread = new DrawingThread(this, holder, mHandler); thread.setRunning(true); thread.start(); } } } </code></pre> <p>Where mWidth is the desired width. Here you may need to change the if statement depending on your specific problem. And MalFormed is a global boolean in your surfaceview.</p> <p>Now it's important to remember, if a change occurs SurfaceChanged() gets called before SurfaceCreated, which means we can easily modify any code which attempts to interact with the thread to suit our above changes.</p> <p>So anywhere where else you are attempting to join or start that background drawing thread you must check first if the surface is MalFormed. E.g.</p> <pre><code>if (thread.getState() == State.TERMINATED){ if(!MalFormed){ holder.removeCallback(this); holder = getHolder(); holder.addCallback(this); thread = new DrawingThread(this, holder,mHandler); thread.setRunning(true); thread.start(); } }else{ if(!MalFormed){ thread.setRunning(true); try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } } </code></pre> <p>Hope I'm in the ballpark somewhere. All the best.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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