0

i need to do a long time job (updating a lot of sql tables) in onstop override of an activity but when i close that activity my apps stops working for several seconds . i tried to use AsyncTask but in that time i get error an error for dialog.dismiss() method in onPostExecute that it says can't attach the dialog to the window ! also i have tried to use services but this method have to be called several times and starting and stopping that service each time didn't work correctly !

i am just mixed up! could you help me with this plz! thanks in advance! :)

Mohsen fallahi
  • 915
  • 1
  • 10
  • 27
  • check this [link](http://stackoverflow.com/questions/19538282/view-not-attached-to-window-manager-dialog-dismiss) – W I Z A R D Apr 08 '14 at 18:19
  • 1
    Service is certainly the way to go here, but it's hard to suggest you anything since you haven't described your actual problem in the least. – Egor Apr 08 '14 at 18:20

1 Answers1

2

IntentService is perfect for such tasks:

http://developer.android.com/reference/android/app/IntentService.html

i have tried to use services but this method have to be called several times and starting and stopping that service each time didn't work correctly !

you simply send jobs to your IntentService, it will take care of initialization and destruction, no need to implement full blown Service.

marcinj
  • 48,511
  • 9
  • 79
  • 100