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

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 1.79 KB  |  hits: 9  |  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. Android ProgressDialog not working.when creating a new activity
  2. public class FLActivity extends ListActivity {
  3.  
  4.     private ProgressDialog mProgressDialog;
  5.  
  6.     @Override
  7.     public void onCreate(Bundle savedInstanceState) {
  8.         super.onCreate(savedInstanceState);
  9.         mProgressDialog = ProgressDialog.show(FLActivity.this, "",
  10.                                               "Loading...");
  11.  
  12.         OtherClass.LongDurationMethodWhichStartsAWorkedThread();
  13.  
  14.         mProgressDiagog.dismiss();
  15.     }
  16. }
  17.        
  18. // in some other class
  19. public static LongDurationMethodWhichStartsAWorkedThread() {
  20.     Runnable r = new FFThread();
  21.     Thread thread = new Thread(r);
  22.  
  23.     thread.start();
  24.     try {
  25.         thread.join();
  26.     } catch (InterruptedException e) {
  27.         e.printStackTrace();
  28.     } catch  (Exception e) {
  29.         e.printStackTrace();
  30.     }
  31. }
  32.        
  33. private class LongOperation extends AsyncTask<String, Void, String> {
  34.  
  35.     @Override
  36.     protected String doInBackground(String... params) {
  37.         // perform long running operation operation
  38.         return null;
  39.     }
  40.  
  41.     /* (non-Javadoc)
  42.      * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
  43.      */
  44.     @Override
  45.     protected void onPostExecute(String result) {
  46.         // execution of result of Long time consuming operation
  47.     }
  48.  
  49.     /* (non-Javadoc)
  50.      * @see android.os.AsyncTask#onPreExecute()
  51.      */
  52.     @Override
  53.     protected void onPreExecute() {
  54.     // Things to be done before execution of long running operation. For example showing ProgessDialog
  55.     }
  56.  
  57.     /* (non-Javadoc)
  58.      * @see android.os.AsyncTask#onProgressUpdate(Progress[])
  59.      */
  60.     @Override
  61.     protected void onProgressUpdate(Void... values) {
  62.       // Things to be done while execution of long running operation is in progress. For example updating ProgessDialog
  63.      }
  64. }