Carlos
Carlos

Reputation: 97

Load WebView in background

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

Answers (1)

Alireza Sharifi
Alireza Sharifi

Reputation: 1162

You can use static variable of WebViewin 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

Related Questions