When to use a Service or AsyncTask or Handler?

前端 未结 5 825
夕颜
夕颜 2020-12-22 23:20

Can someone tell me the TRUE difference?

5条回答
  •  庸人自扰
    2020-12-22 23:37

    • AsyncTask: When I wish to do something without hanging the UI & reflect the changes in the UI.

    E.g.: Downloading something on Button Click, remaining in the same activity & showing progress bar/seekbar to update the percentage downloaded. If the Activity enters the background, there are chances of conflict.

    • Service: When I wish to do something in the background that doesn’t need to update the UI, use a Service. It doesn’t care whether the Application is in the foreground or background.

    E.g.: When any app downloaded from Android Market shows notification in the Status Bar & the UI returns to the previous page & lets you do other things.

提交回复
热议问题