0

Well, I have download an image from network using LWUI ImageDownloadService. While download progress, a Progress Dialog display. I want to stop downloading by pressing Cancel command. But it still downloading. What can i do to stop the download?

My code below

public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == okCommand) {
    final Form resultForm = new Form("Result");
    resultForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    resultForm.show();
    Label mLabel = new Label();
    ImageDownloadService img = new ImageDownloadService("http://datastore04.rediff.com/h1500-w1500/thumb/69586A645B6D2A2E3131/s47kscdm7r4pjx05.D.0.Happy-Valentines-Day-Wallpaper-Image.jpg", mLabel);
    NetworkManager.getInstance().addToQueue(img);
    resultForm.addComponent(mLabel);
    Progress progress = new Progress("Loading", img);
    progress.setDisposeOnCompletion(true);
    progress.show();
}

I have uploaded picture here

Mun0n
  • 4,438
  • 4
  • 28
  • 46
Tan Nguyen
  • 97
  • 1
  • 7
  • possible duplicate of [Lwuit Network Connection Timeout issue](http://stackoverflow.com/questions/17416994/lwuit-network-connection-timeout-issue) – Shai Almog Jul 03 '13 at 17:51
  • can't set timeout, can't stop connection? – Tan Nguyen Jul 04 '13 at 02:15
  • Look this reference. This is my answer http://stackoverflow.com/questions/13966033/how-to-handle-network-thread-calls-and-wait-progress-in-j2me/13969115#13969115 – neb1 Jul 04 '13 at 05:11
  • i try your menthod. but it still downloading – Tan Nguyen Jul 04 '13 at 07:08
  • J2ME doesn't have a way to stop a connection or define a timeout period for a connection. What we tried to do with the connection request is kill the thread making the connection which is something that may or may not work but its pretty much the only workaround for this inherent design flaw in J2ME. – Shai Almog Jul 06 '13 at 17:29

1 Answers1

0

My idea is... put this code in a Thread and in the Command logic stop this thread.

Mun0n
  • 4,438
  • 4
  • 28
  • 46