views:

145

answers:

2

The app I'm working on has a self contained database. The only time I need HTTP request is when the user first loads the app.

I do this by calling a class that verifies whether or not a local DB exists and, if not, create one with the following request:

HttpRequest data = new HttpRequest("http://www.somedomain.com/xml", "GET", this); data.start();

This xml returns a list of content, all of which have images that I want to fetch AFTER the original request is complete and stored.

So something like this won't work:

HttpRequest data = new HttpRequest("http://www.somedomain.com/xml", "GET", this); data.start();
HttpRequest images = new HttpRequest("http://www.somedomain.com/xmlImages", "GET", this); images.start();

Since it will not treat this like an asynchronous request. I have not found much information on adding callbacks to httpRequest, or any other method I could use to ensure operation 2 does not execute until operation 1 is complete.

Any help would be appreciated. Thanks

+1  A: 

There is no built in asynchronous HTTP Request in J2ME. You just do it manually with threads. In particular take a look at the example at the end of the link that does asynchronous messaging.

Byron Whitlock
A: 

Thank you. The link was vague and not precisely what I was looking for, but it did help me down a path that worked. Not sure how efficient it is, but this is the basic result:

    HttpRequest data = new HttpRequest("http://www.somedomain.com/xml", "GET", this); 
    data.start();
    HttpRequest images = new HttpRequest("http://www.somedomain.com/xmlImages", "GET", this); 
    images.start();
    try {
        data.join();
        images.join();
    } catch (InterruptedException e) {

    }

also, the methods in the database class that store the results from the http request are synchronized, for anyone else that may have this issue.

Kai