android design considerations: AsyncTask vs Service (IntentService?)

后端 未结 5 1601
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 16:49

I\'m designing an android app which will need to do the following steps:

  1. user pushes a button or otherwise indicates to \"sync data\".
  2. sync process wi
5条回答
  •  北海茫月
    2020-11-29 17:19

    With AsyncTask if the user goes to another Activity you can't transfer that object to the other Activity so it dies. There are tricks you can play when say the user rotates the screen or something like that, but that doesn't extend to general purpose destruction. AsyncTask can randomly die.

    Google Sync is run as a Service in the background because syncing can take a while to complete. You might need to follow their path and create your own sync service that you can communicate with. Here is some thoughts how to accomplish that:

    http://mylifewithandroid.blogspot.com/2008/01/about-binders.html

    You can definitely communicate between Service and Activity, but it's tricky to do it right.

提交回复
热议问题