views:

58

answers:

2

I have a tabbed interface (one activity per tab) where one tab will be a browser view displaying a webpage. The application loads in a different activity / view, but I want it to begin to download the webpage in the background as soon as the app launches, before the user ever clicks on that tab and initiates that activity.

How can I do this?

Thanks!

-S

A: 

Why not download the page to a file and then allow it to be displayed the file as soon as it is finished downloading?

stealthcopter
Is there a simpler method? Perhaps somehow instantiating the browser view in the background to cause it to begin loading the content?
stormin986
Rather than loading activities into the tabs why not just load Views, then you can just load the webpage into the View before it is displayed?
stealthcopter
Would that require an all-or-nothing approach, i.e., would I have to have ALL tabs be views? My first two tabs are pretty distinct activities so it would seem to be bending the model a bit combing them all in to one activity.Also, let's say I have the webview be a view in my default activity; will the data loaded from the URL in the webview remain loaded, even if I switch to another activity, and eventually return?
stormin986
A: 

I think I have a good sense of how to go about this now, although I haven't worked through the details of implementation yet.

The basic process will include:

  • In my initialization activity, call an AsyncTask to run the HTTP request in a separate thread from the primary UI thread (to ensure UI responsiveness).
  • Store the results of the HTTP request in a simple String object that is a member of my Application object (technically a subclass of Application) to provide application-wide access to the data.
  • Display the previously downloaded String data in a WebView object, using either WebView.loadData() or WebView.loadDataWithBaseUrl()
stormin986
If the user goes to a very large page, and you are using a string you will run out of memory.
stealthcopter
Interesting. Is there a built in limit on the size of a string?
stormin986
Unless there is some built-in limitation on string size, here's what I figure: Given that a string's length is specified as an int, the maximum number of bytes the int can count is 268,435,456. Thus, the max string length is that many characters long. It's hard to believe you would *EVER* come across data served from a web server approaching even a fraction of that size.
stormin986