Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.71 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. First view in android by using progress bar
  2. private class InsertDataTask extends AsyncTask<Void, Void, Void> {
  3.   private final ProgressDialog dialog = new ProgressDialog(Main.this);
  4.  
  5.   // can use UI thread here, and you see we add a progress dialog
  6.   protected void onPreExecute() {
  7.      this.dialog.setMessage("Inserting data...");
  8.      this.dialog.show();
  9.   }
  10.  
  11. // automatically done on worker thread (separate from UI thread)
  12.   protected Void doInBackground(Void... args) {
  13.     //Do background work here
  14.      return null;
  15.   }
  16.  
  17.   // can use UI thread here and we dismiss the progress dialog
  18.   protected void onPostExecute(final Void unused) {
  19.      if (this.dialog.isShowing()) {
  20.         this.dialog.dismiss();
  21.      }