Code example for Handler: Scheduling a delayed task

Methods: postDelayed

0
	   
		Toast 
		  .makeText(this, "Waiting 5 seconds", Toast.LENGTH_SHORT)
		  .show();
		 
		handler.postDelayed(new Runnable() {
		  public void run() { 
		    doTheDownload(); 
		  } 
		}, 5000); 
	} 
	 
	public void doTheDownload() { 
		Intent i=new Intent(this, Downloader.class);
		 
		i.setData(Uri.parse("http://commonsware.com/Android/excerpt.pdf"));
		i.putExtra(Downloader.EXTRA_MESSENGER, new Messenger(handler));
		 
		startService(i);
	} 
}