I have an navigation drawer Activity in which I have made 3 fragments using ViewPager. Each of the fragment has an edit Text, Image button and RecyclerView. The RecyclerView is getting data from a local SQLite database.
On opening the app, I get a Log trace that application skipped XX frames.
(Usually 30-50 frames). Is it normal ?
If not, then what should I do? Can fragments be made using background thread like AsyncTask? Or should I populate RecyclerView in background thread?
Asked
Active
Viewed 265 times
-1

Akshra Gupta
- 31
- 5
-
do you use SQLite on the main thread? – Zun Jun 22 '18 at 07:23
-
use `LoaderManager` to load content – Rahul Jun 22 '18 at 07:24
-
The application is doing too much work in the main thread. move DB operations and other costly operations to background thread – Sarath Kn Jun 22 '18 at 07:25
-
@ZUNJAE yes I am. – Akshra Gupta Jun 22 '18 at 08:07
-
@SarathKn background thread like AsyncTask or is there something else also? – Akshra Gupta Jun 22 '18 at 08:08
-
Don't do that then – Zun Jun 22 '18 at 08:08
-
@RahulKumar LoaderManager is deprecated in API 28 – Akshra Gupta Jun 22 '18 at 08:09
-
every action which performs reads or writes, or that is longer than 16 ms which doesn't require a UI update should be done in a background thread to prevent the app from freezing. – Zun Jun 22 '18 at 08:10
-
@ZUNJAE won't I need to write the data on UI thread? – Akshra Gupta Jun 22 '18 at 08:17
-
no? Why would you? – Zun Jun 22 '18 at 08:19
1 Answers
0
Is it normal?
Nope. Check out Choreographer (start at line 619) if you are eager to find out what's happening behind the scenes.
what should I do? Can fragments be made using background thread like AsyncTask?
You can't do anything with Views
on a background Thread since that would cause a CalledFromWrongThreadException, but what you definitely can and should do is moving all performance-heavy operations like DB read/write to worker Threads. Check out the AsyncTask and AsyncTaskLoader chapter from "Android Developer Fundamentals Course", it will give you a good start on background processing.
Also note that the LoaderManager from the support library is not deprecated.

Droidman
- 11,485
- 17
- 93
- 141