multithreading - Blackberry multi threading issue -



multithreading - Blackberry multi threading issue -

i developping blackberry application communicates server via http requests(javax.microedition.io.httpconnection). on device, user clicks ui items, , device sends requests server, when response comes, ui changes. communication takes place under new thread, while ui thread pushes , pops progressdialogscreen.

the problem sometimes, when response comes , progressdialogscreen popped, ui not alter after couple seconds ui changes. if have requested in between when progressdialogscreen popped , when new screen pushed, there comes mess. first oldest new screen pushed, , newest new screen pushed. , situation can observed server responsing wrong requests. problems occur on simulator , device.

the other problem is, 2 same response returns 1 request. able see these 2 problems on simulator @ logs, have not able see issue on device since can not see logs.

edit:

string utf8response; httpconnection httpconn = null; try{ httpconn = (httpconnection) connector.open(url); httpconn.setrequestmethod(httpconnection.get); httpconn.setrequestproperty("content-type", "text/html; charset=utf8"); if(sessionidcookie != null){ //may throw ioexception, if connection in connected state. httpconn.setrequestproperty("cookie", sessionidcookie); } }catch (exception e) { //... } try{ httpconn.getresponsecode(); homecoming httpconn; }catch (ioexception e) { // ... } byte[] responsestr = new byte[(int)httpconn.getlength()]; datainputstream strm = httpconn.opendatainputstream(); strm.readfully(responsestr); try{ strm.close(); }catch (ioexception e) { // .... } utf8response = new string(responsestr, "utf-8");

if code run, piece of code runs , new screen pushed:

uiapplication.getuiapplication().invokelater(new runnable() { public void run() { vector accounts = parser.parse(utf8response,parser.accounts); if (accounts.size() == 0){ dialogbox.inform(account.no_deposit); return; } currentscreen = new accountlistscreen(accounts); changescreen(null,currentscreen); } }); public void changescreen(final abstractscreen currentscreen,final abstractscreen nextscreen) { if (currentscreen != null) uiapplication.getuiapplication().popscreen(currentscreen); if (nextscreen != null) uiapplication.getuiapplication().pushscreen(nextscreen); }

editv2:

private static void progress(final stoppable runthis, string text,boolean cancelable) { progress = new progressbar(runthis, text,cancelable); thread threadtorun = new thread() { public void run() { uiapplication.getuiapplication().invokelater(new runnable() { public void run() { try{ uiapplication.getuiapplication().pushscreen(progress); }catch(exception e){ logger.log(e); } } }); seek { runthis.run(); } grab (throwable t) { t.printstacktrace(); } uiapplication.getuiapplication().invokelater(new runnable() { public void run() { seek { uiapplication.getuiapplication().popscreen(progress); } grab (exception e) { } } }); } }; threadtorun.start(); }

by way progressbar extended net.rim.device.api.ui.container.popupscreen , stoppable extended runnable

i preferred pop progress bar after new screen prepared , pushed. way there no new request between request , response.

multithreading blackberry

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -