participate


CLDC and MIDP - HELP!"Wait whilst updating" message
<<   Back to Forum  |   Give us Feedback
This topic has 16 replies on 2 pages.    1 | 2 | Next »
viomart
Posts:123
Registered: 7/21/04
HELP!"Wait whilst updating" message   
Apr 5, 2005 10:06 AM

 
Hola! Some of the operation that does my midlet takes like 6 or 7 second.
Per example: an user entry some information and I have to save this information and do lot of math operations with it before go to teh next screen. What I would liek to get is to display a screen or an Alert saying "Please whils updating" or "PLase wait" u know, something like that. And as soon as the application has finsih with the operations, remove that Alert and pass to the next screen automatically. Im thinking about to make create a Thread:
Thread waitWhileProcesing= new Thread();
public void run(){
alert.setTlttle("Wait");
..............
display.setCurrent(alert);
}
and then , when the user click 'OK' to save the data do somethying like:
if (c== CMD_OK){
waitWhileProcesing.start();
//rest of operation

}

My question is: How can I remove that "Wait" alert when the rest of operations are finsih? How can I "kill" that Thread? DO u think teh way I wnat to do it is fine? Do some one has another idea of how to do it?
Thanks/Vio
 
deepspace
Posts:2,943
Registered: 2/2/05
Re: HELP!"Wait whilst updating" message   
Apr 6, 2005 12:42 AM (reply 1 of 16)  (In reply to original post )

 
Something like this:

private boolean working = true;
 
public void stopWorking(){
   working = false;
}
 
public void startWorking(){
   working = true;
   notify();
}
 
public void run(){
   while(true){
      if(working){
         putAlertOnScreen();
         while(working){
            Thread.sleep(500);
         }
      }
      removeAlertFromScreen();
      wait();
   }
}


Note that this is peudocode.. so it needs some tweaking to make it work, but this thread just be used over and over again, without bugging the rest of the system. If you call startWorking() it will show the Alart, and if you call stopWorking() it will remove the alert and wait for the next startWorking().

But why need a thread...

putAlertOnScreen();
.. doStuff();
removeAlertFromScreen();


Might also work, but I guess the thread solution looks nicer and lets the boss think that you did a better job :P
 
viomart
Posts:123
Registered: 7/21/04
Re: HELP!"Wait whilst updating" message   
Apr 6, 2005 1:27 AM (reply 2 of 16)  (In reply to #1 )

 
Thanks a lot for the answer. Im going to try it this morning, just few questions:
private boolean working = true;
About your code:
public void run(){
while(true){
if(working){
putAlertOnScreen();
while(working){
Thread.sleep(500);
}
}
removeAlertFromScreen();
wait();
}
}
putAlertOnScreen(); would be something like:
alert= new Alert()
blabblabla
display.setCurrent(alert);
isnt it?
but :removeAlertFromScreen(); ??
how can I remove an alert kfrom teh screen ? I can not set a time coz I dont know the time that will take the operations (teh task theuser has to wait to be finsih) so I can only write. alert.setTime(Alert.FOREVER) and the a button of "Done " is displayed as well in the screen and teh only way to remove the alert is pressing teh "done " button. So how can I remove the alert without press any buttons? Maybe doing alert= null?
And about teh thread... I create the thread in teh constructor of my class like
t = new Thread();
t.start();
Is that right?
Thanks
 
jappers
Posts:186
Registered: 7/28/04
Re: HELP!"Wait whilst updating" message   
Apr 6, 2005 1:28 AM (reply 3 of 16)  (In reply to #1 )

 
Hm, guess that a boss is also interested in RAM/ROM usage and doesn't care that you're using threads. "Boss, look at my app, I've put some threads in it to simulate multiprocessing blah blah", "What is a thread? Can we make big money by selling threads?" :-)

Anyway, in your case a thread might only be useful when you would like to animate the Alert (show some progress in the Gauge, however in a lot of cases it's difficult to monitor the progress and translate that to a certain x % value in a Gauge...). When 'nothing visual' happens -- let's say for about 5+ seconds, quite some users will think that the app has crashed...
 
deepspace
Posts:2,943
Registered: 2/2/05
Re: HELP!"Wait whilst updating" message   
Apr 6, 2005 1:29 AM (reply 4 of 16)  (In reply to #2 )

 
Why not make a custom Alert and put it on a canvas.
 
viomart
Posts:123
Registered: 7/21/04
Re: HELP!"Wait whilst updating" message   
Apr 6, 2005 1:36 AM (reply 5 of 16)  (In reply to #3 )

 
Hola japper!! :-)
hahaha Exactly , my boss is not a technical person, he doenst care about threads, but he doenst accept that the "SAve Info" alert takes sometimes like 7 seconds!!!! to appear, coz teh mobile is procesing the information and saving it to the record store. (rememner I told you that my midlet is huge so lot of information to process and to store = lot of time)He say "Is not user friendly" and well, he is right, I definitly need to display a "Please Wait" Alert. Is very important. I still dont know how can i remove an alert from teh screen (an alert that has been set like 'setTime(Alert.FOREVER)') without press any button.
Thanks /Vio
 
deepspace
Posts:2,943
Registered: 2/2/05
Re: HELP!"Wait whilst updating" message   
Apr 6, 2005 1:39 AM (reply 6 of 16)  (In reply to #4 )

 
also, removing the thing is as simple as putting it on there:

display.setCurrent(alert);

You just put something else on there in stead of the alert...

Or, you could simply reset the timeout of the alert, from forever to zero, when calculations have finished... This should end the Alert...
 
viomart
Posts:123
Registered: 7/21/04
Re: HELP!"Wait whilst updating" message   
Apr 6, 2005 1:40 AM (reply 7 of 16)  (In reply to #4 )

 
a custom Alert... you mean to dont use the Alert class, and instead create and instance of canvas and wirte text on it and displayed?. Sounds good. But I would like to know if is posible to remove alerts without press any button
 
viomart
Posts:123
Registered: 7/21/04
Re: HELP!"Wait whilst updating" message   
Apr 6, 2005 1:41 AM (reply 8 of 16)  (In reply to #7 )

 
cool, thanks a lot
/Vio
 
deepspace
Posts:2,943
Registered: 2/2/05
Re: HELP!"Wait whilst updating" message   
Apr 6, 2005 1:47 AM (reply 9 of 16)  (In reply to #8 )

 
Even better: As jappers said, display a guage and let it animate (it doest have to display an actual value, but it gives the uses an indication that something is still going on...
 
viomart
Posts:123
Registered: 7/21/04
Re: HELP!"Wait whilst updating" message   
Apr 6, 2005 1:59 AM (reply 10 of 16)  (In reply to #9 )

 
I have never use before the class 'Gauge' and reading it now in teh MIDP2.0 specification. Where should I add this obeject anyway? on an Alert or in a Display? What is your advice?
Thanks/Vio
 
deepspace
Posts:2,943
Registered: 2/2/05
Re: HELP!"Wait whilst updating" message   
Apr 6, 2005 2:03 AM (reply 11 of 16)  (In reply to #10 )

 
look here:

http://developers.sun.com/techtopics/mobility/midp/ttips/alerts20/
 
jappers
Posts:186
Registered: 7/28/04
Re: HELP!"Wait whilst updating" message   
Apr 6, 2005 2:03 AM (reply 12 of 16)  (In reply to #9 )

 
Yep. I'm right now creating some sample that might be useful. However, just showing an Alert, then performing a non-responding task and removing the Alert again, might cause trouble on certain devices.

This is a sample:
Alert lSomeAlert = new Alert("Wait!", "Wait...!", null, AlertType.INFO);
lSomeAlert.setTimeout(Alert.FOREVER);
lSomeAlert.removeCommand(Alert.DISMISS_COMMAND);
    
Display.getDisplay(mMIDlet).setCurrent(lSomeAlert);
    
    System.out.println("-=-=-=-=-");
    for (int i = 0; i < 200; i++)
    {
      for (int k = 0; k < 100; k++)
      {
        System.out.print("-x-");
      }
    }
    System.out.println("-=-=-=-=-");   
  
Display.getDisplay(mMIDlet).setCurrent(this); /* original Form back again... */


However, be aware that 'setCurrent(..)' does not necessarily mean that it will be processed immediately. My Siemens device already starts looping and looping and then decides "ah, we also need an Alert...", and then displays the Alert (alhough the 'printing' already had started).
 
jappers
Posts:186
Registered: 7/28/04
Re: HELP!"Wait whilst updating" message   
Apr 6, 2005 2:34 AM (reply 13 of 16)  (In reply to #12 )

 
The following piece of code illustrates the 'setCurrent(..)' issue:
    Alert lSomeAlert = new Alert("Wait!", "Wait...!", null, AlertType.INFO);
    lSomeAlert.setTimeout(Alert.FOREVER);
   
    Display.getDisplay(mMIDlet).setCurrent(lSomeAlert);
    
    System.out.println("-=-=-=-=-");
    for (int i = 0; i < 20000; i++)
    {
      for (int k = 0; k < 10000; k++)
      {
      }
    }
    System.out.println("1");
    for (int i = 0; i < 20000; i++)
    {
      for (int k = 0; k < 10000; k++)
      {
      }
    }
    System.out.println("2");
    for (int i = 0; i < 20000; i++)
    {
      for (int k = 0; k < 10000; k++)
      {
      }
    }
    System.out.println("3");
    for (int i = 0; i < 20000; i++)
    {
      for (int k = 0; k < 10000; k++)
      {
      }
    }
    System.out.println("4");
    for (int i = 0; i < 20000; i++)
    {
      for (int k = 0; k < 10000; k++)
      {
      }
    }
 
/* somewhere here: the alert will be shown...  */
 
    System.out.println("-=-=-=-=-");
    
    Display.getDisplay(mMIDlet).setCurrent(this);


The alert is shown when already done with looping and looping. Maybe a thread isn't a bad idea though ;-)
 
viomart
Posts:123
Registered: 7/21/04
Re: HELP!"Wait whilst updating" message   
Apr 6, 2005 2:45 AM (reply 14 of 16)  (In reply to #12 )

 
Thank a lot you both, teh article was very useful. My boss took this morning all teh devices for a presentation with some clients so I can not check it in my target until tomorrow, but I'll do some test in the emulator today.
I will let you knwo tomorrow how works on the Nokia,
THANKS A LOT
Vio
 
This topic has 16 replies on 2 pages.    1 | 2 | Next »
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 28
  • Guests : 133

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums