The Source for Java Technology Collaboration

Home » java.net Forums » Mobile & Embedded » LWUIT

Thread: Threads In LWUIT

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is not answered. Helpful answers available: 2. Correct answers available: 1.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 3 - Last Post: Oct 30, 2008 4:25 AM by: Shai Almog
sikeh

Posts: 15
Threads In LWUIT
Posted: Oct 29, 2008 6:06 AM
 
  Click to reply to this thread Reply

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?

Shai Almog
Re: Threads In LWUIT
Posted: Oct 29, 2008 6:33 AM   in response to: sikeh
  Click to reply to this thread Reply

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]


sikeh

Posts: 15
Re: Threads In LWUIT
Posted: Oct 30, 2008 3:45 AM   in response to: Shai Almog
 
  Click to reply to this thread Reply

Hi, Shai,

Do you mean that once performTask() is called, there is no way to stop it?

Regards,
Sike

Shai Almog
Re: Threads In LWUIT
Posted: Oct 30, 2008 4:25 AM   in response to: sikeh
  Click to reply to this thread Reply

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]





 XML java.net RSS