0

I am using IntentService, ResultReceiver mechanism for a long running task and showing progress dialog in my activity during the IntentService run. As the task completes in intentService, I send appropriate resultCode to the Activity in onReceiveResult and dismiss the progress dialog accordingly. Everything works fine except when the device orientation is changed, during which the application crashes as the activity destroys and the Intent service tries to send the resultCode to the destroyed activity.

I don not want to stop the system to recreate my Activity on screen rotation.

How to handle this?

Kaps
  • 2,345
  • 2
  • 26
  • 37
  • how long does the task take to complete. if its asynctask i can provide you a solution and post some of your activity and service code – Raghunandan Jan 23 '14 at 07:28
  • We can achieve this using AsyncTask, but there should be a solution with this approach also. – Kaps Jan 23 '14 at 09:01
  • i have not tired any solution for that. for asynctask i have a solution by alex lookwood – Raghunandan Jan 23 '14 at 09:26

1 Answers1

0

Here is a not recommended but working solution :

Add this line in your manifest :

android:configChanges="orientation"

so it looks like

<activity android:label="@string/app_name" 
        android:configChanges="orientation|keyboardHidden" 
        android:name=".your.package">

More info, see this post

Here is also a more complete answer by Reto Meier here

Community
  • 1
  • 1
bashizip
  • 562
  • 5
  • 14
  • 1
    quoting op "I don not want to stop the system to recreate my Activity on screen rotation.". i already suggested this and deleted it as he does not want to stop the activity recreation – Raghunandan Jan 23 '14 at 07:21