codekarim is just a bunch of reminders for fenuapps.com
private ProgressBar mProgressBar; private Button mButton // On récupère les composants de notre layout mProgressBar = (ProgressBar) findViewById(R.id.pBAsync); mButton = (Button) findViewById(R.id.btnLaunch); // On met un Listener sur le bouton mButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { BigCalcul calcul=new BigCalcul(); calcul.execute(); } }); public class BigCalcul extends AsyncTask{ @Override protected void onPreExecute() { super.onPreExecute(); Toast.makeText(getApplicationContext(), "Début du traitement asynchrone", Toast.LENGTH_LONG).show(); } @Override protected void onProgressUpdate(Integer... values){ super.onProgressUpdate(values); // Mise à jour de la ProgressBar mProgressBar.setProgress(values[0]); } @Override protected Void doInBackground(Void... arg0) { int progress; for (progress=0;progress<=100;progress++) { for (int i=0; i<1000000000; i++){} //la méthode publishProgress met à jour l'interface en invoquant la méthode onProgressUpdate publishProgress(progress); progress++; } return null; } @Override protected void onPostExecute(Void result) { Toast.makeText(getApplicationContext(), "Le traitement asynchrone est terminé", Toast.LENGTH_LONG).show(); } }