Run background task from MainScreen in BlackBerry?

2019-09-19 03:11发布

The issue is how do i make an inception in BlackBerry?

Background: I need to run background service (No Screen Application) after i register a client, after that i need to run safely on the thread.

Thank you very much in advance , code example will be really appreciated.

3条回答
相关推荐>>
2楼-- · 2019-09-19 03:37
Thread thread = new Thread(){
    public void run() {
        // Code for the background service.
    }
};

thread.start();
查看更多
甜甜的少女心
3楼-- · 2019-09-19 03:39

You'll need to create a runnable class that extends thread. (Note, there may be other ways to do this, but this one works.

So you'll need something like

public class BackgroundTask extends Thread{


    private Object _screen;

    public BackgroundTask()
    {

    }

    /**
    * Implementation of Thread.
    */
    public void run()
    {  
        //Do some background task
    }

Now from your main screen, you simply need to call it.

    //Start my background task
new BackgroundTask().start()

Start is a method inherited from the parent Thread class, so it'll take care of spawning a thread for you. Hope this helps.

查看更多
仙女界的扛把子
4楼-- · 2019-09-19 03:41

The Blackberry-way to do it is to use invokeLater():

        int _id = -1;
        Application _app = UiApplication.getUiApplication();

        ...

        _id = _app.invokeLater(new Runnable() {
            public void run() {
                // do something - in 10 seconds
                _id = -1;
            }
        }, 10*1000L, false);
查看更多
登录 后发表回答