0

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.

一二三
  • 21,059
  • 11
  • 65
  • 74

3 Answers3

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.

frencha
  • 41
  • 4
  • In hindsight it's not necessary. It gives your thread access to your main screen if you wanted to push an update to it, but really it's optional. Apologies for the ambiguity (I'm new at BB programming myself) – frencha Jul 31 '11 at 17:49
1
Thread thread = new Thread(){
    public void run() {
        // Code for the background service.
    }
};

thread.start();
bluish
  • 26,356
  • 27
  • 122
  • 180
sanrodari
  • 1,602
  • 2
  • 13
  • 23
0

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);
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416