Run background task from MainScreen in BlackBerry?

≡放荡痞女 提交于 2019-12-25 04:04:29

问题


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.


回答1:


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.




回答2:


Thread thread = new Thread(){
    public void run() {
        // Code for the background service.
    }
};

thread.start();



回答3:


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


来源:https://stackoverflow.com/questions/6887601/run-background-task-from-mainscreen-in-blackberry

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