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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom
Accepted Solution

global dialog not popping up when it should

[ Edited ]

hi all,

 

mbytes= 350 

Longreadnumberofkbytes= 250

readalert1file=90 //Text file data

DataLimit= 300  //Text file data

CurrentNumberofDataUsed= mbytes-Longreadnumberofkbytes;

ButtonField Save = new ButtonField ("Save",ButtonField.FOCUSABLE);
FieldChangeListener Listener = new FieldChangeListener() {
   public void fieldChanged(Field field, final int context) {
      ButtonField  Button = (ButtonField) field;
      if (Button.getLabel().equals("Save")){
         MCBT = new Thread(MakeChangesBackgroundThread);
         MCBT .start();
      }
   }
}
Save.setChangeListener(Listener); 
add(Save);

private Runnable MakeChangesBackgroundThread = new Runnable(){
   public void run(){
      while(true){
         long datalimitsum1 = Longreadalert1file/100;
         long finalansweralert1= datalimitsum1* LongDataLimit;
         if(!(readalert1file==null)){
	    if(!(readalert1file.equals(""))){
               if(finalansweralert1==CurrentNumberofDataUsed && CurrentNumberofDataUsed==finalansweralert1){
                  synchronized(UiApplication.getEventLock()){
                     System.out.println("Dialog thread starting");
		     UiEngine ui = Ui.getUiEngine();
		     Screen screen = new Dialog(Dialog.D_OK, "You Have Reached You'r "+readalert1file+"% alert",Dialog.OK, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION),Manager.VERTICAL_SCROLL);
                     ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_QUEUE);
		  }try{ 
                       Thread.sleep(30000/2);
		  }catch (InterruptedException e){
                       e.printStackTrace();
	          }
                }else{
                }
             }else{
             }
         }else{
         }
      }
   }
}

 

My Above code should push the global dialog when the

finalansweralert1

 is equal to 270. Can anyone please tell me What I am doing wrong?? TheDialog displays imediately after pushing the save button and not when 

finalansweralert1

is equal to

CurrentNumberofDataUsed

 

Thank you

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: global dialog not popping up when it should

If I understand this correctly, your question seems to be a straight Java question.  You have this statement:

 

               if(finalansweralert1==CurrentNumberofDataUsed && CurrentNumberofDataUsed==finalansweralert1){

 

and you think that CurrentNumberofDataUsed is 270 and finalansweralert1 is 0, and so the if should not be executed. 

 

Is this a correct statement of the problem?

 

To find out what is wrong with your logic, can you not just put a break point on the if statement and check what the values are?

Highlighted
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: global dialog not popping up when it should

hi peter, 

 

Some of my variables values werent correct they were displaying 0. Fixed it now. 

 

Thank you

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: global dialog not popping up when it should

Can you please mark as solved then? 

 

And perhaps try the debugging trick before posting? 

 

Cheers

Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: global dialog not popping up when it should

I was stuck for two days on end, luckily a developer at the office was kind enough to assist me. i have marked the thread as solved. I only post something if i am stuck for days on end.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: global dialog not popping up when it should

I understand that, but there is a huge difference between being stuck because the Java API is not doing what you expect and stuck because you have a logic error in your code.  The debugger is a a powerful tool for helping you trace logic errors, I was suggesting that you get familiar with that so that you do not have to post logic problems here again that could be solved using the debugger.  And you won't be stuck for days before posting....  Win for all!  Hope that is clear.  Cheers

Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: global dialog not popping up when it should

okay, Thanks peter. have a good one.