开发者

How to stop ui background thread on blackberry

I've addded 5 button in horizontalFieldManger.

When i click the button i gets image url from server there after i get the image.

I loaded the image in on verticalfiedlManager on the same screen..

My code is.

    Thread loadImageThread = new Thread()
    {
        public void run()
        {
            if(Imagethread)
            {
                try 
                {
                    final Vector url = new Vector();
                    HttpConnections httpConnection = new HttpConnections(path+suffix);
                    DataInputStream _inputStream = new DataInputStream(httpConnection.StreamConnection());
                    getXMLObjects(_inputStream);
                    _inputStream.close();
    开发者_JAVA百科                UiApplication.getUiApplication().invokeLater(new Runnable() 
                    {
                        public void run() 
                        {
                            feedListItem = ListFeedHandler.item;
                            int Size = feedListItem.size();
                            for (int i = 0; i < Size; i++) 
                            {
                                url.addElement(newsBean.getURL());
                            }
                        }
                    });

                    UiApplication.getUiApplication().invokeLater(new Runnable()
                    {
                        public void run()
                        {
                            loadPicture(url);
                        }
                    });
                } 
                catch(Exception e)
                {
                    e.printStackTrace();
                }
            }
        }
    };
    loadImageThread.start();

In loadPicture(url) method. i get image and load on verticalfiledmager.

When i click second button, i delete all imaged on verticafiledmanager and reload which is get from second button.

Its working fine.

but my problem is when i click buttons two,three, four continuously , its load one by one. I need only the images which is last pressed button.


Something like this..

int id = -1; 
...
if(id != -1) {
  UiApplication.getUiApplication().cancelInvokeLater(id);
  id = -1;
}
id =  UiApplication.getUiApplication().invokeLater(new Runnable() 
 {
 public void run() { 
  .....
  id = -1; //when invokeLater task finished normally
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜