user345602
user345602

Reputation: 598

Android thread main exiting

I have thread in "onCreate" which is getting content from web. While the content is getting, I have progress dialog.

new Thread() {

     public void run() {

     Get_content() ;


    handler.sendEmptyMessage(0);
     }

     }.start();

But if I rotate the display (to landscape mode) while this is running, my application gets Force close . In the log I have this:"thread main exiting due to uncaught exception"

Here is my log:

W/dalvikvm(17144): threadid=3: thread exiting with uncaught exception (group=0x40013140) E/AndroidRuntime(17144): Uncaught handler: thread main exiting due to uncaught exception E/AndroidRuntime(17144): java.lang.IllegalArgumentException: View not attached to window manager E/AndroidRuntime(17144): at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:356) E/AndroidRuntime(17144): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:201) E/AndroidRuntime(17144): at android.view.Window$LocalWindowManager.removeView(Window.java:400) E/AndroidRuntime(17144): at android.app.Dialog.dismissDialog(Dialog.java:268) E/AndroidRuntime(17144): at android.app.Dialog.access$000(Dialog.java:69) E/AndroidRuntime(17144): at android.app.Dialog$1.run(Dialog.java:103) E/AndroidRuntime(17144): at android.app.Dialog.dismiss(Dialog.java:252) E/AndroidRuntime(17144): at com.webservice.KursnaLista$1.handleMessage(KursnaLista.java:77) E/AndroidRuntime(17144): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(17144): at android.os.Looper.loop(Looper.java:123) E/AndroidRuntime(17144): at android.app.ActivityThread.main(ActivityThread.java:3948) E/AndroidRuntime(17144): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(17144): at java.lang.reflect.Method.invoke(Method.java:521) E/AndroidRuntime(17144): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782) E/AndroidRuntime(17144): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) E/AndroidRuntime(17144): at dalvik.system.NativeStart.main(Native Method) I/dalvikvm(17144): threadid=7: reacting to signal 3 I/ActivityManager( 59): Process com.webservice (pid 17144) has died.

Upvotes: 0

Views: 1792

Answers (1)

Robby Pond
Robby Pond

Reputation: 73484

What is happening is on orientation change, the activity is killed and re-created. But since you started a thread and the thread is still running, it is not killed, and when it finishes and tries to close the Progress Dialog, that causes the FC because the progress dialog doesn't exist. This is a pretty common problem, you can check out the droid-fu library that tries to fix this, or you can be smarter with your Threaded task (like if it is going to take a decent amount of time to complete, then maybe put it in a background service).

Upvotes: 2

Related Questions