App crashes on configuration changes

485 Views Asked by At

I am working on a part of my app where it runs an AsyncTask and because of this I wanted to handle configuration changes correctly.

Using the code from this link (which differs a bit from the code on the website) I was able to get the AsyncTask to run on screen rotations on a phone under API (I am using the backward compatible libraries for the fragments).

However I then tested this on my device and every time I rotate the device I get the below error (logged via logcat):

08-21 07:33:31.634: W/Surface(488): java.lang.Throwable
08-21 07:33:31.634: W/Surface(488):     at android.view.Surface.<init>(Surface.java:337)
08-21 07:33:31.634: W/Surface(488):     at com.android.server.wm.ScreenRotationAnimation.<init>(ScreenRotationAnimation.java:258)
08-21 07:33:31.634: W/Surface(488):     at com.android.server.wm.WindowManagerService.startFreezingDisplayLocked(WindowManagerService.java:12303)
08-21 07:33:31.634: W/Surface(488):     at com.android.server.wm.WindowManagerService.updateRotationUncheckedLocked(WindowManagerService.java:7697)
08-21 07:33:31.634: W/Surface(488):     at com.android.server.wm.WindowManagerService.updateRotationUnchecked(WindowManagerService.java:7602)
08-21 07:33:31.634: W/Surface(488):     at com.android.server.wm.WindowManagerService.updateRotation(WindowManagerService.java:7565)
08-21 07:33:31.634: W/Surface(488):     at com.android.internal.policy.impl.PhoneWindowManager.updateRotation(PhoneWindowManager.java:6793)
08-21 07:33:31.634: W/Surface(488):     at com.android.internal.policy.impl.PhoneWindowManager$MyOrientationListener.onProposedRotationChanged(PhoneWindowManager.java:760)
08-21 07:33:31.634: W/Surface(488):     at android.view.WindowOrientationListener$ScreenOrientationEventListenerImpl.onSensorChanged(WindowOrientationListener.java:534)
08-21 07:33:31.634: W/Surface(488):     at android.hardware.SystemSensorManager$ListenerDelegate$1.handleMessage(SystemSensorManager.java:256)
08-21 07:33:31.634: W/Surface(488):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 07:33:31.634: W/Surface(488):     at android.os.Looper.loop(Looper.java:175)
08-21 07:33:31.634: W/Surface(488):     at com.android.server.ServerThread.run(SystemServer.java:1774)

EDIT

This happens when the progress dialog box is visible and AsyncTask is running while a configuration change was made.

As a work-around, I used an IntentService.

However, I still want to know what caused it the original failure?

1

There are 1 best solutions below

0
Léo Lam On

This is not my answer but OP's, which was posted in the question itself. I've moved it into this community wiki answer and taken the liberty to "improve" it a bit.


I have found this to be due to ProgressDialog and running the AsyncTask while a configuration change was made.

To fix this, I ended up using an IntentService instead now.