|
Replies:
3
-
Last Post:
Oct 30, 2008 4:25 AM
by: Shai Almog
|
|
|
|
|
|
|
Threads In LWUIT
Posted:
Oct 29, 2008 6:06 AM
|
|
|
Hi,
I'm coding an application with snapshot function.
I would like the snapshot action to be invoked in background, and meanwhile prompt a dialog to user saying the progress.
I find an article "Progress Indicator & Threads In LWUIT" by Shai: http://lwuit.blogspot.com/2008/05/progress-indicator-threads-in-lwuit.html
And write a SnapshotTask which extends BackgroundTask:
public void taskStarted() {
dialog = new Dialog("Progress");
dialog.addComponent(new Label("please wait..."));
dialog.showModeless();
}
public void taskFinished() {
dialog.dispose();
previousForm.update();
previousForm.show();
}
public void performTask() {
try {
byte[] img = videoControl.getSnapshot(null);
System.out.println("size of image in bytes: " + img.length);
// release resource
captureForm.release();
attachments.addElement(attachmentService.createPhotoAttachment(img));
} catch (MediaException ex) {
ex.printStackTrace();
}
}
The question is that If I add a "Cancel" Command to the dialog, the dialog can be disposed, but how do I terminate the Task itself?
|
|
|
|
|
|
|
Re: Threads In LWUIT
Posted:
Oct 29, 2008 6:33 AM
in response to: sikeh
|
|
|
|
|
Hi, perform task will need to check a "canceled" flag. stop() was deprecated in Java due to portability issues.
> Hi, > > I'm coding an application with snapshot function. > > I would like the snapshot action to be invoked in background, and > meanwhile prompt a dialog to user saying the progress. > > I find an article "Progress Indicator & Threads In LWUIT" by Shai: > http://lwuit.blogspot.com/2008/05/progress-indicator-threads-
> in-lwuit.html > > And write a SnapshotTask which extends BackgroundTask: > > public void taskStarted() {
> dialog = new Dialog("Progress");
> dialog.addComponent(new Label("please wait..."));
> dialog.showModeless();
> }
>
> public void taskFinished() {
> dialog.dispose();
> previousForm.update();
> previousForm.show();
> }
>
> public void performTask() {
> try {
> byte[] img = videoControl.getSnapshot(null);
> System.out.println("size of image in bytes: " +
> img.length);
> // release resource
> captureForm.release();
> attachments.addElement
> (attachmentService.createPhotoAttachment(img));
> } catch (MediaException ex) {
> ex.printStackTrace();
> }
> }
>
> > The question is that If I add a "Cancel" Command to the dialog, the > dialog can be disposed, but how do I terminate the Task itself? > [Message sent by forum member 'sikeh' (sikeh)] > > http://forums.java.net/jive/thread.jspa?messageID=313741 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net > For additional commands, e-mail: users-help@lwuit.dev.java.net >
Shai Almog http://lwuit.blogspot.com/
[att1.html]
|
|
|
|
|
|
|
|
Re: Threads In LWUIT
Posted:
Oct 30, 2008 3:45 AM
in response to: Shai Almog
|
|
|
Hi, Shai,
Do you mean that once performTask() is called, there is no way to stop it?
Regards, Sike
|
|
|
|
|
|
|
|
Re: Threads In LWUIT
Posted:
Oct 30, 2008 4:25 AM
in response to: sikeh
|
|
|
|
|
Hi, in Java ME there is no thread.stop method and that method is deprecated in Java SE. This is unrelated to LWUIT, you can turn on a flag in your code which is what we (and everyone else) do when we provide a cancelable task.
> Hi, Shai, > > Do you mean that once performTask() is called, there is no way to > stop it? > > Regards, > Sike > [Message sent by forum member 'sikeh' (sikeh)] > > http://forums.java.net/jive/thread.jspa?messageID=313977 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net > For additional commands, e-mail: users-help@lwuit.dev.java.net >
Shai Almog http://lwuit.blogspot.com/
[att1.html]
|
|
|
|
|