import org.apache.http.*;
(you probably need a whole bunch more imports here)
public class MyWebPage
{
static Document dom;
Document instance()
{
if(dom == null)
{
URI uri = URIUtils.createURI("http", host, port, path,
query, fragment);
HttpGet httpGet = new HttpGet(uri);
HttpResponse response = mClient.execute(httpGet);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200)
{
throw something at someone;
}
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(is);
}
return dom;
}
}
In this scheme if Android feels the need to reload your entire app,
then you'll refetch the web page, but otherwise any Activity can get
to the parsed document via: MyWebPage#instance();
Oh, and it's likely that you want to actually fetch the web page in a
background task to avoid nasty timeouts but that's a whole 'nother
topic. See android.os.AsyncTask to get started on that one.
Dale
On Sun, Feb 13, 2011 at 9:34 PM, Heath <heath....@gmail.com> wrote:
--
I get up every morning determined to both change the world and have
one hell of a good time. Sometimes this makes planning my day
difficult.
-E. B. White
-Heath Borders
heath....@gmail.com
Twitter: heathborders
http://heath-tech.blogspot.com
-Heath Borders
heath....@gmail.com
Twitter: heathborders
http://heath-tech.blogspot.com
Score! Thanks.
-Heath
On Feb 14, 2011 5:20 PM, "Ben Oberkfell" <bober...@gmail.com> wrote:
There's an Application class to help you maintain global application state.Application and Activity both inherit from Context, so conceivably you should be able to pass in the application when you create the WebView, and then store the WebView on the Application.You can declare a class name in the manifest for your application using "android:name" :<application android:icon="@drawable/icon" android:label="@string/app_name" android:name="com.foobar.app.YourApp">Then just define a YourApp class that extends Application. The rest will be done for you in terms of instantiating that particular class on startup.In your Activity, you can call getApplicationContext() to get at the Application and grab your WebView.
On Monday, February 14, 2011 at 4:36 PM, Heath Borders wrote:
>
> Option 1 isn't really feasible ...
-Heath Borders
heath....@gmail.com
Twitter: heathborders
http://heath-tech.blogspot.com