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: Force Close when opening app after pressing home button and here: Android crash when app is closed and reopened. 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.
I am using a surfaceview with the surfaceCreated & surfaceDestroyed methods used by LunarLander.
Thanks in Advance.
LogCat:
Log1:<br>
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)
Log2:
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)
SurfaceDestroyed Methods:
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");
}
SurfaceCreated Method:
public void surfaceCreated(SurfaceHolder holder) {
thread.initLevel();
thread.setRunning(true);
thread.start();
//thread.notify();
}
EDIT:
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.