android - Thread vs Handler for polling -
i need polling thread perform network operations every 5 mins. came following 2 solution. better , why? looking have minimum cpu , battery usage.
pollthread = new thread(){ public void run(){ while(toggle) { // stuff sleep(five_minutes); } } }; pollthread.start();
or
runnable dostuffrunnable = new runnable() { @override public void run() { // stuff handler.postdelayed(this, five_minutes); } }
the answer depends on whether using handler handle other tasks well. if not, there won't difference; there still thread wakes every 5 minutes want. if handler handles other tasks, using handler more efficient having separate thread each task, requires 1 thread, , may have optimizations respect processor usage.
Comments
Post a Comment