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 loader
s data, service
s , 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
orfragment
; - 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
Post a Comment