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

The Archive Base Latest Questions

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

my app get crashed when the surfaceview goes to background by recieving call or

  • 0

my app get crashed when the surfaceview goes to background by recieving call or exit and return to the app. i read that surfacedestroyed doesnt get call on these situations but
the solutions that were given didnt work for me.
i will be gratefull if someone can help me with my code.
thanks

public GameLoopThread(GameView view)
{

this.view=view;
}
public void setRunning (boolean run)
{
    running=run;
}
@Override
public void run() {

    long ticksPerSecond=1000/FPS;
    long startTime;
    long sleepTime;
    while (running)
    {
        Canvas c=null;
        startTime=System.currentTimeMillis();
        try {
        c=view.getHolder().lockCanvas();
        synchronized (view.getHolder()) {
            view.onDraw(c);
        }

        } catch (Exception e) {
            // TODO: handle exception
        }
        finally{
            if(c!=null)
            view.getHolder().unlockCanvasAndPost(c);
        }
        sleepTime=ticksPerSecond-(System.currentTimeMillis()-startTime);
        try
        {if(sleepTime>0)
            sleep(sleepTime);
        else
            sleep(10);

        }
        catch(Exception e){}

        synchronized (mPauseLock) {
            while (!running) {
                try {
                    mPauseLock.wait();
                } catch (InterruptedException e) {
                }
            }
        }
    }

and in the surfaceview:
 public void surfaceDestroyed(SurfaceHolder holder) {
 if(gameLoopThread.isAlive())
            {
                boolean retry = true;
                gameLoopThread.setRunning(false);
                while (retry) {
                    try {
                        gameLoopThread.join();
                        retry = false;
                    } catch (InterruptedException e) {
                    }
                }
            }
            }

            @Override
            public void surfaceCreated(SurfaceHolder holder) {
                if(!gameLoopThread.isAlive())
                    {           

                     gameLoopThread.setRunning(true);
                     gameLoopThread.start();

                    }
            }

maybe the logcat will help:

10-22 09:35:06.310: DEBUG/Buddies—————————>(10985): Service:OnReceive ACTION_HOME_RESUME called
10-22 09:35:06.315: DEBUG/AndroidRuntime(3275): Shutting down VM
10-22 09:35:06.315: WARN/dalvikvm(3275): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): FATAL EXCEPTION: main
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): java.lang.NullPointerException
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at tomer.idunku3.GameView$1.surfaceDestroyed(GameView.java:126)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at android.view.SurfaceView.reportSurfaceDestroyed(SurfaceView.java:613)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at android.view.SurfaceView.updateWindow(SurfaceView.java:498)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at android.view.SurfaceView.updateWindow(SurfaceView.java:407)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:217)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at android.view.View.dispatchWindowVisibilityChanged(View.java:4080)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:720)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:720)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at android.view.ViewRoot.performTraversals(ViewRoot.java:790)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at android.view.ViewRoot.handleMessage(ViewRoot.java:1868)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at android.os.Handler.dispatchMessage(Handler.java:99)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at android.os.Looper.loop(Looper.java:123)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at android.app.ActivityThread.main(ActivityThread.java:3691)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at java.lang.reflect.Method.invokeNative(Native Method)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at java.lang.reflect.Method.invoke(Method.java:507)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
10-22 09:35:06.315: ERROR/AndroidRuntime(3275): at dalvik.system.NativeStart.main(Native Method)
10-22 09:35:06.320: ERROR/(18080): Dumpstate > /data/log/dumpstate_app_error

  • 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-26T07:50:19+00:00Added an answer on May 26, 2026 at 7:50 am

    I dont think this part is necessary:

    synchronized (mPauseLock) {
            while (!running) {
                try {
                    mPauseLock.wait();
                } catch (InterruptedException e) {
                }
            }
        }
    

    If you use this, you’ll need to notify in order to release the lock on wait();
    But try using the same code, with out the synchronized(mPauseLock)

    EDIT:

    The solution for your problem when you press on the Home button, the application crashes, do this:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        gameView = new GameView(this);
        setContentView(gameView); 
    }
    
    @Override
    public void onPause(){
        super.onPause();
        gameView.gameLoopThread.setRunning(false);
        finish();
    }
    

    And in GameView (SurfaceView) create the constructor:

    public GameLoopThread gameLoopThread;
    
    public GameView(Context context) {
        super(context);
        gameLoopThread = new GameLoopThread(this);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When my app crashes, I get a crash report that takes 5 minutes to
My computer crashed recently. We have a Delphi app that takes a lot of
Does a destructor get called if the app crashes? If it's an unhandled exception
An app I'm writing always crashes on a clients computer, but I don't get
How can my app get a valid last time connected to domain timestamp from
I am just testing an app to get data off our web server, previously
So I'm working on a Rails app to get the feeling for the whole
I'm thinking in build a iPhone app for get recipes. So, I'm looking for
I have been trying for 4 days to get app-engine and grails working together
I am adding the ability for users of my web app to get credit

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.