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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:06:12+00:00 2026-06-08T22:06:12+00:00

I write a simple game with the following structure. Main xml layout have user

  • 0

I write a simple game with the following structure. Main xml layout have user View:

<?xml version="1.0" encoding="utf-8"?>
<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" >

    <com.sokolovlev.UFOtest03.MenuView
            android:id="@+id/menuView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

</RelativeLayout>

This View have two files. First is user MenuView:

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) { }
        }
    }
}

And second file is this draw manager:

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);
                }
            }
        }
    }
}

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.
enter image description here

I don’t understand, where there is a reloading which influences such on my drawings! Help please!

  • 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-06-08T22:06:14+00:00Added an answer on June 8, 2026 at 10:06 pm

    To solve this problem, I need to save the settings and restart my surface. Then load the settings. (See LunarLander Example)

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

Sidebar

Related Questions

Problem I want ot write a simple 1D RTS game and have the following
I'm planing to write simple iOS game and I'm curious which view control to
I'm writing a simple game, and I have main frame with 4 JPanels placed
This is a very simple game I'm trying to write but I have a
I have begun to write a simple platform game in java. As a test,
I had a task to write simple game simulating two players picking up 1-3
I had a task to write simple game simulating two players picking up 1-3
I'm trying to write a simple game based on selecting the correct answer (A
I'm trying to write a simple Resource Manager for the little hobby game I'm
I'm trying to write a snake game. It's pretty simple, there's an array of

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.