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
privateboolean working = true;
publicvoid stopWorking(){
working = false;
}
publicvoid startWorking(){
working = true;
notify();
}
publicvoid 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().
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
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...
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
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
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...
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
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).
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 ;-)
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 »