Android : Using Handler but still meet NetworkOnMainThreadException <p>I do some network thing, and I understand I cannot do it on main thread. So, I put it into Handler. Here is my code:</p> <pre><code>handler = new Handler(); handler.postDelayed(new OrderTask(this, url), 10 * 1000); // periodically run every 10 seconds. </code></pre> <p>And here is my Runnable class:</p> <pre><code>public class OrderTask implements Runnable { OrderFragment fragment; String url; public OrderTask(OrderFragment fragment, String url) { this.fragment = fragment; this.url = url; } @Override public void run() { synchronized (fragment.orders) { fragment.orders = Order.loadServerOrders(url); // network code here } fragment.adapter.notifyDataSetChanged(); } } </code></pre> <p>But when It runs, it wll throw exception : <code>NetworkOnMainThread</code> at line <code>loadSeverOrder</code>. I cannot explain why. Please help me figure this.</p> <p>Thanks :)</p>