In my case I have 18 pages of a book. Some of the pages contain a lot of text data and the pager struggles in switching between these pages. Is there a workaround?
Asked
Active
Viewed 113 times
0
-
Use Traceview and figure out where your problem is. – CommonsWare Aug 15 '14 at 16:22
-
When switching between the pages, from the Logcat it indicates the application may be doing too much work on its main thread. Is this Adapter the right one to use given the number of pages I have? – RicNjesh Aug 15 '14 at 17:06
-
Most likely, your `PagerAdapter` choice is not your problem. Most likely, your implementation of your pages is your problem. Enable `StrictMode` to make sure that you are not doing disk or network I/O on the main application thread. Beyond that, use Traceview and [other tools](http://www.curious-creature.org/docs/android-performance-case-study-1.html) to figure out where your time is actually being spent. – CommonsWare Aug 15 '14 at 17:11
1 Answers
0
From the documantation:
This version of the pager is more useful when there are a large number of pages, working more like a list view. When pages are not visible to the user, their entire fragment may be destroyed, only keeping the saved state of that fragment. This allows the pager to hold on to much less memory associated with each visited page as compared to FragmentPagerAdapter at the cost of potentially more overhead when switching between pages.
So maybe try to use the FragmentPagerAdapter
instead.

Simon Marquis
- 7,248
- 1
- 28
- 43
-
Are 18 pages considered few? I tend to think these pages are many to have all in memory at once given amount of text data some of these pages have. That's why I opted to use the FragmentStatePagerAdapter. – RicNjesh Aug 15 '14 at 17:03
-
What is your text data? How is it displayed? Maybe you could centralized the data. – Simon Marquis Aug 15 '14 at 17:06
-
Its just text displayed from an internal database. What do you mean centralise it? – RicNjesh Aug 15 '14 at 17:10
-
Displaying text should not be as expensive as you said... You said your device struggles when swiping pages, so maybe you could try to load the data only once and not once for every pages – Simon Marquis Aug 15 '14 at 17:13
-
I usually load all the data on creating the activity, load it to an array and work with it. Am not sure how the state page adapter reloads pages not in view but when the text on a page exceeds a certain length of scrolling, page switching is not smooth – RicNjesh Aug 15 '14 at 18:33
-
Are you using TextView to render your data? Are you using formatted text (html like?) – Simon Marquis Aug 15 '14 at 18:49
-
So if you are only using TextView, you should really take a look at traceView to figureout where the problem comes from – Simon Marquis Aug 15 '14 at 19:22