Help! Why is the onComplete method running synchronously, not asynchronously?
findViewById(R.id.button8).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final ProgressDialog pd = new ProgressDialog(MainActivity.this); final Handler h = new Handler() { public void handleMessage(Message msg) { pd.setMessage("Загрузка..."+msg.what); if(msg.what==20) pd.dismiss(); } }; Thread t = new Thread(new Runnable() { public void run() { for(int i =0; i<=10; i++){ try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) {} h.sendEmptyMessage(i); } VKRequest request = VKApi.wall().get( VKParameters .from("domain", "serd_donbassa", "count", "200", "offset", "0")); request.executeWithListener(new VKRequestListener() { public void onComplete(VKResponse response) { for(int i =10; i<=20; i++){ try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) {} h.sendEmptyMessage(i); } } }); } }); pd.setMessage("Загрузка..."); pd.setCancelable(false); pd.show(); t.start(); } }); This code updates only up to 10, and then hangs for 10 seconds (the ProgressDialog stops spinning), and then disappears. It follows from the above that the method runs asynchronously. How to fix it?