回到黑莓上的mainScreen时如何停止Browserfield requestContent()方法 [英] how to stop Browserfield requestContent() method when back to mainScreen on blackberry

查看:110
本文介绍了回到黑莓上的mainScreen时如何停止Browserfield requestContent()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击一个按钮时,在下一个屏幕中,我已使用线程加载了browserfield requestcontent().

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

并且我添加了browserfield监听器.

and i've added browserfield listener.

当单击后退"按钮时,我来到了第一个屏幕.但是在后台,requestContent正在执行.如何阻止它??

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

我在onClose()方法上编写代码

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();
}

我的代码是.

        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.

推荐答案

我认为足够了:

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);
  }
}

在onClose方法中:

In onClose method:

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

如果您有任何疑问,请进入名为"黑莓和Java知识共享中心"的聊天室,以澄清您和我们的疑问.

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

这篇关于回到黑莓上的mainScreen时如何停止Browserfield requestContent()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆