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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:41:03+00:00 2026-05-20T04:41:03+00:00

I am programming a game on android. I’m using a Thread while calling a

  • 0

I am programming a game on android. I’m using a Thread while calling a Surface View class to update and draw my game. Inside the update I wanted to start an activity based on if the game has just started and this would launch my MENUS.

My Thread for the most part..

    while (myThreadRun) {
        Canvas c = null;
        try {
            gameTime = System.currentTimeMillis();
            c = myThreadSurfaceHolder.lockCanvas(null);
            synchronized (myThreadSurfaceHolder) {
                // Update Game.
                myThreadSurfaceView.onUpdate();
                // Draw Game.
                myThreadSurfaceView.onDraw(c);

You can see there where I am updating the game… here is onUpdate();

protected void onUpdate() {

    // Test if menu needs to be displayed.
    while (thread.getMenu()) {
        // Test if menu activity has been started.
        if (thread.getMenuRunning() == false) {
            Intent menuIntent = new Intent(this.getContext(), MyMenu.class);
            ((Activity) cxt).startActivityForResult(menuIntent, 1);
            thread.setMenuRunning(true);
        }
    }

I am using a while loop because if I didn’t use it the thread just keeps going.

Basically I just don’t know how to implement my menus using a thread as a game loop. Everywhere I look it seems like that’s best practice.

In my menu activity I just display the menu layout and a few buttons and when the person wants to start the game it uses finish() to go back to my thread where they play the game.

I am very new to this so any insight will be helpful,

Thanks

  • 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-20T04:41:03+00:00Added an answer on May 20, 2026 at 4:41 am

    Your SurfaceView thread should concern itself solely with drawing the game’s current state to the SurfaceView. Anything not to do with that rendering – especially things like deciding whether to run a menu activity – belongs on the UI thread.

    So don’t do all that stuff in your onUpdate()… do it in your game’s Activity class, in response to the Menu button being pressed or something. You should be pausing your rendering thread from GameActivity.onPause() and resuming it in GameActivity.onResume() so the game isn’t churning away while the menu is showing.

    (And onResume() is also a good time for the game to react to the changes the user just made via the menu activity).

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

Sidebar

Related Questions

With reference to this programming game I am currently building. I am using WPF
I am talking about a small game engine using C# for game programming. So,
I'm currently programming very simple game for Android (API level 7) to discover and
I am recently getting into Android programming and want to make a simple game
I am looking into game programming in Java to see if it is feasible.
I want to get started game programming in C/C++, or C# with DirectX or
I'd like to give Objective-C a try in game programming. The problem is I'd
I want to study Cocos2d, seems it's a good framework for iPhone game programming.
I'm programming an online game for two reasons, one to familiarize myself with server/client
I'm working on a game (C#) that uses a Robocode-like programming model: participants inherit

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.