Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple game bug
    primarykey
    data
    text
    <p>I write a simple game with the following structure. Main xml layout have user View:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/menuRL" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;com.sokolovlev.UFOtest03.MenuView android:id="@+id/menuView" android:layout_width="fill_parent" android:layout_height="fill_parent" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>This View have two files. First is user MenuView:</p> <pre><code>package com.sokolovlev.UFOtest03; import android.content.Context; import android.util.AttributeSet; import android.view.SurfaceHolder; import android.view.SurfaceView; public class MenuView extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mSurfaceHolder; //Draw surface public static MenuManager mMenuManager; //Draw manager public MenuView(Context context, AttributeSet attrs) { super(context, attrs); // Surface events registration mSurfaceHolder = getHolder(); mSurfaceHolder.addCallback(this); mMenuManager = new MenuManager(mSurfaceHolder, context); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { mMenuManager.initPositions(height, width); } @SuppressWarnings("static-access") @Override public void surfaceCreated(SurfaceHolder holder) { mMenuManager.setRunning(true); try { mMenuManager.start(); } catch (Exception e) { } } @SuppressWarnings("static-access") @Override public void surfaceDestroyed(SurfaceHolder holder) { boolean retry = true; mMenuManager.setRunning(false); while (retry) { try { mMenuManager.join(); retry = false; } catch (InterruptedException e) { } } } } </code></pre> <p>And second file is this draw manager:</p> <pre><code>package com.sokolovlev.UFOtest03; import ... public class MenuManager extends Thread { private SurfaceHolder mSurfaceHolder; private static boolean mRunning; private int _screenHeight; private int _screenWidth; private ... Context c; private ... public MenuManager(SurfaceHolder surfaceHolder, Context context) { mSurfaceHolder = surfaceHolder; mRunning = false; c = context; ... } public static void setRunning(boolean running) { mRunning = running; } @Override public void run() { while (mRunning) { Canvas canvas = null; try { // подготовка Canvas-а canvas = mSurfaceHolder.lockCanvas(); canvas.drawRGB(0, 0, 0); synchronized (mSurfaceHolder) { //All drawing } } catch (Exception e) { } finally { if (canvas != null) { mSurfaceHolder.unlockCanvasAndPost(canvas); } } } } } </code></pre> <p>Everything works fine! (step №1) But if I press central button, or I have incoming call, or I call task manager (step №2) and go back to my app - I haven't my drawing, only black screen (step №3). But if I go next to step №2 and then in my app, I see that everything works. <img src="https://i.stack.imgur.com/Lm77g.jpg" alt="enter image description here"></p> <p>I don't understand, where there is a reloading which influences such on my drawings! Help please!</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.
 

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