prey / prey-android-client

Android client for the Prey anti-theft software.
http://preyproject.com
GNU General Public License v3.0
426 stars 184 forks source link

Convert AsyncTasks to IntentService #90

Open yulin2 opened 9 years ago

yulin2 commented 9 years ago

Hi prey-android-client developers, I'm doing research on Android async programming, particularly on AsyncTask and IntentService. AsyncTask can lead to memory leak and losing task result when GUI is recreated during task running (such as orientation change). This article describe the problems very well.

We discussed with some Android experts and they agree with this issue, and claim that AsyncTask can be considered only for short tasks (less than 1 second). However, using IntentService (or AsyncTaskLoader) can avoid such problems since their lifecycles are independent from Activity.

In prey-android-client, most of the AsyncTasks are declared as non-static inner classes of Activity/Preference. So the above issue can occur (especially for relatively long tasks).

I refactored 7 AsyncTasks in prey-android-client to IntentService (in 7 commits), with the help of a refactoring tool we developed. Do you think using IntentService should be better in these 7 scenario? Do you want to merge this pr? Thanks.

yulin2 commented 9 years ago

I sent this pr several days ago. Any comments/suggestions on the changes?