puoi usare AsyncTask..
controlla questo codice funzionante...
per chiamare AsyncTask usa new BackGround().execute();
la classe privata BackGround estende AsyncTask
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Instructions.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Void doInBackground(Void... arg0) {
// here is your background process...
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if (pDialog.isShowing())
pDialog.dismiss();
}
}