问题
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