Reputation: 97
I have 2 activities in my app: 1-Home page 2-WebView
The activity 2 (WebView) is really slow to load (about 10secs). Can I load the activity 2 in background? So when I start activity 2 I have the WebView loaded.
I am thinking about Pager Adapter with Fragments but I don't know if this is the best way.
Upvotes: 1
Views: 220
Reputation: 1162
You can use static
variable of WebView
in first Activity
but it will cause memory-leak the best approach is to use Fragment
in ViewPager
and use setOffscreenPageLimit(1)
setOffscreenPageLimit(int limit)
Set the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state.
which means you are in you primary fragment but the next fragment (left one if there is one and the right one of course) will also be ready and loaded. but if you have third fragment and you swiped to third one , the the first one will be destroyed .
Upvotes: 2