Heavy tasks in Android should be executed in background threads. Heavy tasks are:
- database tasks
- work with images, audio, video
- fetching and parsing internet data
- some extensive calculations (very rare in most apps)
What else can be considered as a heavy task and should be executed in background thread?
I am getting an ANR error and I need to know which tasks Android interprets as heavy tasks.
If it takes more than couple of milliseconds, it should be executed in a background thread.
Courtesy of Project Butter in Android 4.1, the Android UI now updates at 60fps, meaning that there is ~16ms to do everything that is needed to render a frame. The OS needs some of that time to do the actual rendering. If you take more than a few milliseconds, you may skip a frame, causing “janky” behavior. Even on earlier versions of Android, the effect can be seen — it’s just going to be more jarring on Jelly Bean, because everything else is smoother.