'How to fix "The application may be doing too much work on its main thread" in Android? [duplicate]

When I'm fetching vast amount of data (in form of videos) from cache the app responds after a long delay.

How do I resolve or fix it?

Logcat: The application may be doing too much work on its main thread



Solution 1:[1]

While performing long running or computation heavy tasks, you should prefer doing it on a background thread (i.e, separate from the UI thread).

You will see ANRs on the app if the UI thread is kept busy for more than 5 seconds, but even for less than 5 seconds there will be a noticeable lag and delay of user actions (click, scroll) and a similar message in logs as you are seeing (Choreographer : Skipped XXX frames! The application may be doing too much work on its main thread.).

Some of the ways to such perform tasks on background thread are :

Also, be careful while updating the UI from a background thread as Android UI toolkit is not thread-safe.


Edit :

For off-loading tasks from main thread, you can also use :

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1