我的要求是在應用程序開始點解析兩個網址,這兩個網址具有需要在我的應用程序中顯示的數據。我這樣做是通過在一個數組中保存兩個urls並在後臺線程中運行for循環,然後將值插入到後臺線程的數據庫中,這是否是正確處理問題的正確方法?在應用程序啓動黑莓手機上運行多個網址
我已經發布我的代碼如下,任何形式的幫助是歡迎:)任何形式的
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);
}
幫助是值得歡迎的
AY
我認爲當RequestMethod是GET時,url應該包含類似於www.site.com?variable = value' – pheromix
是的,我不能公開這個url,所以我保留了一些虛擬的東西,但是我的擔心如果我對我所做的事情是正確的。調用多個網址是否正確? – ayachama
如果你知道多線程的概念,那麼很容易做到這一點。 – alishaik786