android - Most concise way to run a simple background task? -


i've seen @ least 5 patterns through can have code run in worker thread. simple:

new thread(new runnable() {     public void run() {       //     } }).start(); 

we can extend asynctask; have asynctaskloader , other loaders data, services , on.

i assume each 1 of has advantages i'm not discussing here. i'm wondering is: appropriate, concise way run simple action?

defining simple:

  • quite short action, <1s;
  • no need deal ui elements;
  • one line command or such, looks inappropriate extend asynctask new class;
  • no need notified success of task in activity or fragment;
  • no need display progress;
  • just need have kind of return.

what thought @ first was:

boolean myreturn;  new thread(new runnable() {     public void run() {       myreturn = myextensivetask();     } }).start();  public boolean myextensivetask() { ... } 

would correct (or possible)? how should done?

using bolts utility framework (used facebook , parse.com), simple that:

task.callinbackground(new callable<myreturntype>() {     @override     public myreturntype call() {         myreturntype obj = dowork();         return obj;     } }); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -