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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:15:19+00:00 2026-05-26T16:15:19+00:00

I am trying to make a game for android. It is based on a

  • 0

I am trying to make a game for android. It is based on a 2d map, which the user can move around the screen. On the screen are several buttons, for example ‘Shop’. When I user presses the button, I would like to fill the screen with a shop interface.

So far my approach has been as follows:

I have a mapView, and a map thread

  • public class MapView extends SurfaceView implements SurfaceHolder.Callback {}

  • public class MapThread extends Thread { ... }

The map thread periodically calls the onDraw method in MapView, which draws the map to the screen, whilst event listeners in MapView deal with moving the map.

For the shop, I have a similar setup, with a ShopThread and a ShopView. When the shop button is pressed, my idea is to stop the MapThread, and start the ShopThread. This would mean only the ‘onDraw’ method of ShopView will be called, allowing me to draw the shop interface.

In reponse to the button press I have the following code:
(I pass the activity between each of the views via the variable topPage)

    mapThread.isRunning = false; //stop the map thread
    setVisibility(INVISIBLE);
    // add showView to the activity and start the ShopThread
    topPage.addContentView(shopView,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                        ViewGroup.LayoutParams.FILL_PARENT) );
        shopView.startThread();

My problem is that the game freezes for a while when trying to access the shop. The screen just remains black and doesn’t respond for around 30 seconds to a minute. I will also get the ‘force close’ or ‘wait’ error message from the OS. If I press wait, the ShopView will occasionally start working completely correctly.

I have narrowed it down to the run method in my ShopThread class.

public void run() {
    Canvas c;
    while (isRunning){
        c = null;
        try {
            c = ShopView.getHolder().lockCanvas(null);
            synchronized (ShopView.getHolder()) {
                if(c != null)
                ShopView.onDraw(c);
            }
        } finally {
            if( c != null){
                ShopView.getHolder().unlockCanvasAndPost(c);
            }
        }
    }
}

The line c = ShopView.getHolder().lockCanvas(null); is simply returning null. I have placed Log.v statements in the other updateThreads and they appear to have all stopped. What is keeping a lock on the canvas, is there something I am missing?

  • 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-05-26T16:15:19+00:00Added an answer on May 26, 2026 at 4:15 pm

    I found the problem. I managed to fix it, but I am unsure why is was a problem in the first place.

    I originally created a ShopView object in my MapView class and started the ShopThread manually when I wanted to start drawing the shop to the canvas. Instead of this, I changed it so that the ShopView thread was created and started in the surfaceCreated() function

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

Sidebar

Related Questions

i am trying to make some kind of reflex like game for android, which
I'm trying to make a triangle (isosceles triangle) to move around the screen and
I'm trying to make an NDK-based game work on Android ICS. It worked fine
I'm, trying to make a simple 3D game for Android, and I want to
I am just messing around trying to make a game right now, but I
I'm trying to make a game (using irrlicht engine with c++) where you can
I'm trying to make a tetris game for android to help learn game programming
I'm trying to make a game with Qt, but i can't load an image.
I'm trying to make a game where the user is supposed to drag a
I am trying to make a turn-based board game that will be run on

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.