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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:42:03+00:00 2026-06-12T07:42:03+00:00

Checking the LunarLander example it uses that code for resume the drawer thread: public

  • 0

Checking the LunarLander example it uses that code for resume the drawer thread:

public void surfaceCreated(SurfaceHolder holder) {
    // start the thread here so that we don't busy-wait in run()
    // waiting for the surface to be created
    thread.setRunning(true);
    thread.start();
}

and this for end:

public void surfaceDestroyed(SurfaceHolder holder) {
    // we have to tell thread to shut down & wait for it to finish, or else
    // it might touch the Surface after we return and explode
    boolean retry = true;
    thread.setRunning(false);
    while (retry) {
        try {
            thread.join();
            retry = false;
        } catch (InterruptedException e) {
        }
    }
}

But when I execute the project, press the home button and resume the application it crashes with

 java.lang.IllegalThreadStateException: Thread already started.
    at java.lang.Thread.start(Thread.java:1045)
    at com.example.android.lunarlander.LunarView.surfaceCreated(LunarView.java:862)
    at android.view.SurfaceView.updateWindow(SurfaceView.java:533)
    at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:226)
    at android.view.View.dispatchWindowVisibilityChanged(View.java:5839)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:945)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:945)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:945)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:945)

I’ve seen this method for handling the background thread in other examples but it crashes. What is the problem with it?

  • 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-12T07:42:05+00:00Added an answer on June 12, 2026 at 7:42 am

    Your thread is still running, you dont stop it correctly i guess.
    You have to interrupt your thread or thats how i solved it. So instead of using setRunning and a boolean to make your thread run you use something like this:

    to start it:

    public void surfaceCreated(SurfaceHolder holder) {
        thread.start();
    }
    

    In the thread:

    public void run() {
    
        try {
            while (true) {
                // code here
            }
        }
        catch (InterruptedException e) {
             //disable stuff here
        }
    }
    

    And to stop it:

    public void surfaceDestroyed(SurfaceHolder holder) {
        thread.interrupt();
    }
    

    I just typed this quickly but it should give you an idea.

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

Sidebar

Related Questions

Checking few RDBMS I find that things like SELECT COUNT (a), SUM (b) FROM
Checking the documentation online I saw that it is pass by reference. Can someone
Checking the datagrid example here http://www.silverlight.net/content/samples/sl4/toolkitcontrolsamples/run/default.html see the datagrid section It says that if
when checking the source code of a site on firefox I got this on
After checking out code for the first time from a repository into Eclipse using
Checking the simple code var http = require('http'); var server = http.createServer(function(req, res){ console.log(Got
While checking my code with splint, I got one problem. At first i got
When checking that variables passed via GET and POST are correct, I might have
Checking for cookies with code below if (!isset($_COOKIE['auth'])) { header('Location:' . wsurl); } My
Checking data with targeting some sentence in when condition using xslt -1.0 example sentence

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.