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
Trusted Contributor
NGeldenhuys
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

Please use plain text.
Developer
peter_strange
Posts: 19,595
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?

Please use plain text.
Trusted Contributor
NGeldenhuys
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

Please use plain text.
Developer
peter_strange
Posts: 19,595
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

Please use plain text.
Trusted Contributor
NGeldenhuys
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.

Please use plain text.
Developer
peter_strange
Posts: 19,595
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

Please use plain text.
Trusted Contributor
NGeldenhuys
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.

Please use plain text.