Force Close on Re-Open
<p>I am having issues with my app where it force closes when ever it is interrupted by a phone call or the home key is pressed. When the user goes back to the app it they receive the force close message. I have read the following question and tried to answer suggested: <a href="http://stackoverflow.com/questions/5255981/force-close-when-opening-app-after-pressing-home-button/5256618#5256618">Force Close when opening app after pressing home button</a>  and here: <a href="http://stackoverflow.com/questions/5318847/android-crash-when-app-is-closed-and-reopened/5319629#5319629">Android crash when app is closed and reopened</a>.
The answers posed in the second question did not help and when I added wait()it gave me a force close when the app opened and when I added notify() it gave me a force closed when ever I left the app. I am out of ideas and now looking for so see if anyone might have a solution to this problem. </p>

<p>I am using a surfaceview with the surfaceCreated &amp; surfaceDestroyed methods used by LunarLander. </p>

<p>Thanks in Advance.</p>

<p>LogCat:</p>

<pre><code>Log1:&lt;br&gt;
07-08 02:18:32.284: ERROR/AndroidRuntime(627): Uncaught handler: thread main exiting due to uncaught exception
07-08 02:18:32.354: ERROR/AndroidRuntime(627): java.lang.IllegalThreadStateException: Thread already started.
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at java.lang.Thread.start(Thread.java:1322)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at com.android.hitmanassault.HitmanView.surfaceCreated(HitmanView.java:115)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at android.view.SurfaceView.updateWindow(SurfaceView.java:454)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:189)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at android.view.View.dispatchWindowVisibilityChanged(View.java:3782)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:692)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:692)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at android.view.ViewRoot.performTraversals(ViewRoot.java:706)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at android.os.Looper.loop(Looper.java:123)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at android.app.ActivityThread.main(ActivityThread.java:4363)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at java.lang.reflect.Method.invokeNative(Native Method)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at java.lang.reflect.Method.invoke(Method.java:521)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-08 02:18:32.354: ERROR/AndroidRuntime(627):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>Log2:</p>

<pre><code>07-08 02:21:39.805: ERROR/AndroidRuntime(663): Uncaught handler: thread main exiting due to uncaught exception
07-08 02:21:39.854: ERROR/AndroidRuntime(663): java.lang.IllegalMonitorStateException: object not locked by thread before notify()
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at java.lang.Object.notify(Native Method)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at com.android.hitmanassault.HitmanView.surfaceDestroyed(HitmanView.java:135)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at android.view.SurfaceView.reportSurfaceDestroyed(SurfaceView.java:488)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at android.view.SurfaceView.updateWindow(SurfaceView.java:413)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:189)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at android.view.View.dispatchWindowVisibilityChanged(View.java:3782)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:692)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:692)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at android.view.ViewRoot.performTraversals(ViewRoot.java:706)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at android.os.Looper.loop(Looper.java:123)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at android.app.ActivityThread.main(ActivityThread.java:4363)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at java.lang.reflect.Method.invokeNative(Native Method)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at java.lang.reflect.Method.invoke(Method.java:521)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-08 02:21:39.854: ERROR/AndroidRuntime(663):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>SurfaceDestroyed Methods:</p>

<pre><code>public void surfaceDestroyed(SurfaceHolder holder) {
        Log.d(TAG, "Surface is being destroyed");   
        boolean retry = true;
        thread.setRunning(false);
        thread.notify();
        while (retry) {
            try {
                thread.join();
                                //thead.notify();  ---I would get rid of the join part
                retry = false;  
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }               
        }
        Log.d(TAG, "Thread was shut down cleanly");
    }
</code></pre>

<p>SurfaceCreated Method:</p>

<pre><code>public void surfaceCreated(SurfaceHolder holder) {
        thread.initLevel();
        thread.setRunning(true);    
        thread.start();
                //thread.notify();      
    }
</code></pre>

<p>EDIT:<br>
where I have the join at tried switching with notify, wait. I also tried putting notify before the try and putting wait where join is. </p>
