My requirement is to parse two urls at application start point, these two urls have data that is required to be displayed in my application. I am doing this by keeping two urls in a array and running a for loop in the background thread and then insert the values into database in background thread, is it correct way of approaching the problem?
I have posted my code below, help of any kind is welcomed :)
public StartConnecton(SplashScreen splashScreen)
{
urls = new String[2];
urls[0] = "http:xxxxxx.com";
urls[1] = "http:yyy.com";
_dbIRef = new ClassDatabase(1);
_dbIRef.setSID(46);
_splashScreen = (SplashScreen)splashScreen;
_classDatabase = new ClassDatabase();
}
public void run()
{
int size = urls.length;
for(int i = 0; i < size;i++)
{
if(i==0)
{
_id= 1;
}else if(i==1)
{
_id = 0;
}
try{
String conn = this.getConnectionString();
con = (HttpConnection)Connector.open(urls[i]+getConnectionString());
con.setRequestMethod(HttpConnection.GET);
con.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC- 1.0");
System.out.println("CONNECTION!!!!!!!!!!!"+con);
code = con.getResponseCode();
System.out.println("CODE!!!!!!!!!!!"+code+"ID"+_id);
if ( code == HttpConnection.HTTP_OK)
{
is = con.openInputStream();
int length = (int) con.getLength();
new Parser(is,_id);
is.close();
con.close();
}
}catch(Exception e)
{
System.out.println("EXCEPTION!!!!!!!!!!"+e);
}
}
_classDatabase.delete("Delete from topnews where sid = 46");
_classDatabase.insertTopNews();
_classDatabase.insertTabBar();
_classDatabase.insertGalleryInfo();
_topNewsScreen = new TopNewsScreen("TopNews");
_splashScreen.swapScreen(_topNewsScreen);
}
Help of any kind is welcomed
A Y