Don't think you'd need a new class as it's quite simple to spawn threads.
B4X:
public static void playAsTask(String s){
final String ss = s;
Task task = new Task<Void>() {
@Override public Void call(){
Player player = new Player();
player.play(ss);
return null;
}
};
new Thread(task).start();
}
It was not the best example, I just cut/pasted from a program I wrote.
The main parts are
B4X:
Task task = new Task<Void>() { <<< a void Task ie it returns nothing to the caller
@Override public Void call(){
// do what you need to here
return null; <<< even though it returns nothing you must return a null
};
new Thread(task).start(); <<< this starts the thread running
I don't think it can be useful to get what I need.
I need something like "all this code (which could be a "class") must run in its own thread". Almost as it was a project inside a project.
A "multi-room" chat could be an example. Each room should work in its own thread (and it should "communicate" with other threads, but for this I think that thread safe maps should be enough or, at least, I could write something on disk or database).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.