how to stop Browserfield requestContent() method when back to mainScreen on blackberry

和自甴很熟 提交于 2019-12-13 20:15:58

问题


When i click a button, in next screen i've loaded browserfield requestcontent() using thread.

and i've added browserfield listener.

when click back button , i came to first screen. But in background, requestContent is executing. how to stop it.?

i write the code on onClose() method

public boolean onClose()
{
for(int i=0;i<=Thread.activeCount();i++)
    {
        if(Thread.currentThread().isAlive())
        {
            Thread.currentThread().interrupt();
        }   
    }
return super.onClose();
}

My code is.,

        new Thread(new Runnable() 
        {
            public void run() 
            {
                loadWebContent(path);
            }
        }).start();

private void loadWebContent(String path) 
{

    final VerticalFieldManager vfm = new VerticalFieldManager(HORIZONTAL_SCROLL|VERTICAL_SCROLL)
    {
        protected void sublayout(int maxWidth, int maxHeight)
        {

            super.sublayout(maxWidth, (Display.getHeight()-47));
            setExtent(maxWidth, (Display.getHeight()-47));

        }
    };

    BrowserFieldConfig myBrowserFieldConfig = new BrowserFieldConfig();

    myBrowserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);


    myBrowserField = new BrowserField(myBrowserFieldConfig);


    myBrowserField.addListener(new BrowserFieldListener() 
    {
        public void documentLoaded(BrowserField browserField,Document document) throws Exception 
        {

            UiApplication.getApplication().invokeLater(new Runnable() 
            {
                public void run() 
                {
                    try
                    {


                        mainlayout.delete(spinner);
                        mainlayout.add(myBrowserField); 
                                                                                 myBrowserField.setZoomScale(1.0f);

                    }
                    catch (Exception e) 
                    {
                        System.out.println("++ "+e);
                    }
                }
            });
        }
    });

myBrowserField.requestContent(path);

}

Pls help how to stop execution when back to first screen.


回答1:


I think this is Enough:

public class LoadingScreen extends MainScreen 
{   
  ButtonField click;
  String url;
  BrowserField browserField;
  public LoadingScreen() 
  {
        url="http://www.google.com";
    browserField=new BrowserField();        
    add(browserField);              
    browserField.requestContent(url);
  }
}

In onClose method:

public boolean onClose() 
{       
    return super.close();
}

If you have any doubbts come on chat room named "Knowledge sharing center for blackberry and java" to clarify your and our doubts.



来源:https://stackoverflow.com/questions/7606462/how-to-stop-browserfield-requestcontent-method-when-back-to-mainscreen-on-bla

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!