Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
duksunkim
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified
Accepted Solution

Information updating screen problem

[ Edited ]

Hi all,

 

I'm having a problem with network function.

What I'm tring to do is:

1) make http call every second until satisfy certain condition -- this works fine.

2) display information on popupscreen whenever http call finished but this one gets displayed last time only.

  not displaying every second. So I can not show status of processing, but it shows only result.

3) below is my code.(sorry for the ugly code.)

 

Please help me to get a solution for this.

Thanks.

Calling method: public int makeCallLoop() { boolean running=true; int statusCode; int result = this.SUCCESS; StringBuffer sb = new StringBuffer("Making call"); while (running) { connThread = new ConnectionThread(); connThread.start(); connThread.post(Globals.blaster_url, "action_type=" + Globals.ACT_TYPE_BLASTER_CALL_STATUS + "&" + "uid=" + uid + "&sessionid=" + sessionId + "&list="+getStatusData()); while (connThread.sending) { try { //Status.show( sb.append(".").toString() ); Thread.sleep(1000);//100 } catch (Throwable e) { connThread.stop();//Dk 090708 System.out.println("----------------makeCallLoop(), connThread Sleep exception: " + e); Status.show( "Please try again." );

} } if (connThread.httpRespCode== HttpConnection.HTTP_OK) { JSONParser jparser = new JSONParser(); statusCode = jparser.parseBlasterGetStatus(Globals.receivedContent); uid = jparser.uid; sessionId = jparser.sessionId; if (statusCode == 0) { running = false; result = this.SUCCESS; search_no = jparser.search_result; //Status.show("We got some answers for you." + "- www.heycosmo.com -"); BlasterCallStatus(); ----- --- //Display Blaster call status private void BlasterCallStatus() { VerticalFieldManager manager = new VerticalFieldManager(VERTICAL_SCROLL| VERTICAL_SCROLLBAR | Field.FIELD_HCENTER|Field.USE_ALL_WIDTH) { protected void sublayout(int width, int height) { super.sublayout(Display.getWidth()-20,Display.getHeight()-25); setExtent(Display.getWidth()-20, Display.getHeight()-25); setPosition(0,0); } }; VerticalFieldManager headerMgr = new VerticalFieldManager(); _popupMenu = new PopupScreen(manager, DEFAULT_CLOSE|PopupScreen.VERTICAL_SCROLL) {

// popup screen methods are here

}; cnt=0; LabelField nullLabel0 = new LabelField(" ", LabelField.NON_FOCUSABLE) { }; BitmapField liveCallStat = new BitmapField(BlasterMain.middle_off, BitmapField.FOCUSABLE|BitmapField.FIELD_VCENTER) { public void onUnfocus(){ if(liveCallStatB) setBitmap(BlasterMain.middle_on); else setBitmap(BlasterMain.middle_off); invalidate(); super.onUnfocus(); } protected void paint(Graphics g) {

} }; headerMgr.add(nullLabel0); headerMgr.add(liveCallStat); manager.add(headerMgr); LabelField [] list = new LabelField[search_no]; { JSONParser jparser = new JSONParser(); int status = jparser.parseBlasterGetStatus(Globals.receivedContent); search_no = jparser.search_result; Enumeration keys = jparser.rowObj.keys(); //iterate through each key and get the respective value phoneInfo = new String [jparser.row.size()]; cnt=0; while(keys.hasMoreElements()) { String key = keys.nextElement().toString(); try { phoneInfo[cnt]= jparser.rowObj.getString(key); } catch (JSONException e) { Status.show("You received wrong data format, please try again."); } subStr = Utils.split(phoneInfo[cnt], "|"); phone = subStr[1]; .....

list[cnt] = new LabelField (subStr[0], LabelField.FOCUSABLE| LabelField.FIELD_HCENTER|LabelField.USE_ALL_WIDTH) { .... public void paint(Graphics g) { XYRect xy = g.getClippingRect(); if(xy.y < 0) { throw new IllegalStateException("Clipping rectangle is wrong."); } String [] subStr; //String phone = ; int startLine=1; g.setFont(f12b); g.setColor(0xffffff); g.drawText(this.getText(), 0, 0);//Name g.setColor(0x425173); g.setFont(f12b); g.drawText(phone, 2, 13);//Phone number g.setFont(f); g.drawBitmap(Display.getWidth()-20-optionImg.getWidth(), 0, optionImg.getWidth(), optionImg.getHeight(), optionImg, 0,0); g.setColor(0x0054a6); g.drawText(callStatus, Display.getWidth()-20-optionImg.getWidth()+ (optionImg.getWidth()-f.getAdvance(callStatus))/2, startLine*optionImg.getHeight()); super.paint(g); } }; manager.add(list[cnt]); cnt++; } //manager.add(listMgr); UiApplication.getUiApplication().pushScreen(_popupMenu); //bodyMgr.add(listMgr); } }

 

Message Edited by duksunkim on 01-16-2009 07:40 AM
Message Edited by duksunkim on 01-16-2009 07:40 AM
Message Edited by duksunkim on 01-16-2009 10:26 AM
Message Edited by duksunkim on 01-16-2009 10:28 AM
Please use plain text.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Information updating screen problem

[ Edited ]

No hard feelings, man. But the code is really awful.

 

There is a common rule. If you do something and it appears ugly - there is 1000% chance that there is at least one bug. It is true not only for programming :smileyhappy:

 

For the first - plan your application algorithm, use design patterns (MVC for example), split your long code to methods, verify everything step by step and you'll get working and reliable code.

 

Even if someone advises you where is the catch in this big piece of code you provided - it won't help you to really understand the problem and make a good product.

Message Edited by tbilisoft on 16-01-2009 12:53 PM
Please use plain text.
Developer
duksunkim
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: Information updating screen problem

I agree with you.

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: Information updating screen problem

Can I suggest that you provide a smaller section of code that shows the problem, in other words, remove all the redundant stuff (as far as this problem is concerned), run that code to demonstrate that you still have the problem, then give us that code.  I suspect that in your code, all the parser and display stuff is redundant as far as this problem is concerned, so remove it all.

 

Just a thought.

Please use plain text.
Developer
duksunkim
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: Information updating screen problem

Hi Peter,

 

I've cut and edited unnessary stuffs.

The main problem is that makeCallLoop() calls BlasterCallStatus() every second to update status.

So logically BlasterCallStatus() get called to bring the popupscreen every second but although it is being called (verified) it BlasterCallStatus() is not showing up but it pops up at last call.

 

So I'm assuming that this is because of network access by makeCallLoop() method. Actually makeCallLoop() makes http request before call BlasterCallStatus().

 

Is the network access block popupScreen in this code?

Please use plain text.
Administrator
MSohm
Posts: 14,241
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Information updating screen problem

To start off with, if this loop is running a number of times you shouldn't display a bunch of popup screens every second.  Each popup screen creates its own thread, which can cause you issues.

 

What Is - TooManyThreadsError
Article Number: DB-00474

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800783/What_Is...

 

Note that IO connections should be made in their own thread.

 

Support - Application stops responding when opening a connection
Article Number: DB-00159

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/Support...

 

If your application is running in the background, see this link:

 

How To - Alert a user from a Background application
Article Number: DB-00407

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800608/...

 

If it is running in the foreground, see this link:

 

How to - Update a screen on the Main Event Thread
Article Number: DB-00136

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800256/...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
mores
Posts: 4
Registered: ‎02-10-2009
My Device: Not Specified

Re: Information updating screen problem


tbilisoft wrote:

 

For the first - plan your application algorithm, use design patterns (MVC for example), split your long code to methods, verify everything step by step and you'll get working and reliable code.



java.util.Observable does not appear to be available when compiling

Is there a MVC framework that does run on the BlackBerry ?
Please use plain text.
Developer
rihan007
Posts: 455
Registered: ‎01-14-2009
My Device: Apple iPhone 3GS 16GB

Re: Information updating screen problem


MSohm wrote:

To start off with, if this loop is running a number of times you shouldn't display a bunch of popup screens every second.  Each popup screen creates its own thread, which can cause you issues.

 

What Is - TooManyThreadsError
Article Number: DB-00474

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800783/What_Is...



 

if each popupscreen creates its own thread what is the solution to show status screens very often. and then destroy the thread when the popup screen is dismissed?Now as i create a lot of popupscreens i get toomanythreads error

Please use plain text.
Developer
rihan007
Posts: 455
Registered: ‎01-14-2009
My Device: Apple iPhone 3GS 16GB

Re: Information updating screen problem

Please help friends. thanks
Please use plain text.
Developer
SamuelD
Posts: 166
Registered: ‎01-14-2009
My Device: Curve 8330

Re: Information updating screen problem

You can create your own popup screen and just modify the status message. You'll have just one threat for the popup screen.
Thank you, have a nice day.

--
Samuel D.
Please use plain text.