The solution is very simple, for anyone who runs into this in the
future...

As Kumar stated when the phone is rotated the activity is destroyed
and recreated - you don't have to play with Android for very long
before you realize that.

What I didn't know is you can override that behavior by adding this to
to the activity node in the android manifest:
android:configChanges="orientation"

there is more information about it here:
http://groups.google.com/group/android-developers/browse_thread/thread/c2ff370c99317236/f955457847fc69b8#f955457847fc69b8

and

http://developer.android.com/reference/android/app/Activity.html#ConfigurationChanges

but basically instead of destroying the activity the method
onConfigurationChanged method is called.  I'm not sure what other
problems this creates but this seems to be better default behavior
than destroying and recreating everything....

-Aaron

On May 10, 11:15 am, Aaron <aobrien...@gmail.com> wrote:
> Thanks Mike, that was very helpful!
>
> I'll See if I can use the info to get my example working correctly,
> and post it for the next person...
>
> On May 10, 9:05 am, Mike dg <vinb...@gmail.com> wrote:
>
>
>
>
>
> > Evan Charlton wrote a great article that might help you.
>
> >http://evancharlton.com/thoughts/rotating-async-tasks/
>
> > -Mike dg
>
> > On May 10, 12:37 am, Aaron <aobrien...@gmail.com> wrote:
>
> > > I have a managed ProgressDialog that show the status as tasks are
> > > moving along.  The Activity.show is kicked off by an AsyncTask
> > > progressUpdates and the final Activity.closeDialog is called through
> > > the AsyncTask as well.  Everything works beautifully as long as the
> > > screen is not rotated...
>
> > > What am I doing wrong? I thought having the Activity manage my dialog
> > > would solve this for me... Here is the code I'm playing with:
>
> > > public class Enter extends Activity {
> > >         ProgressDialog progressDialog;
> > >         private final static int PROGRESS_DIALOG_ID = 1;
>
> > >     @Override
> > >     public void onCreate(Bundle savedInstanceState) {
> > >         super.onCreate(savedInstanceState);
> > >         setContentView(R.layout.main);
>
> > >         Button button = (Button)findViewById(R.id.progressbar_button);
>
> > >         button.setOnClickListener(new View.OnClickListener(){
>
> > >                         @SuppressWarnings("unchecked")
> > >                         public void onClick(View v) {
>
> > >                                 Enter.this.showDialog(PROGRESS_DIALOG_ID);
> > >                                 new AsyncTask(){
>
> > >                                         @Override
> > >                                         protected Object 
> > > doInBackground(Object... params) {
> > >                                                 progressDialog.setMax(30);
> > >                                                 for (int a = 0; a < 30; 
> > > a++){
> > >                                                         
> > > publishProgress(new Integer((a+1)));
> > >                                                         try {
> > >                                                                 
> > > Thread.sleep(1000);
> > >                                                                 
> > > Log.d("Enter", "Click: " + a);
> > >                                                         } catch 
> > > (InterruptedException e) {
> > >                                                                 
> > > e.printStackTrace();
> > >                                                         }
> > >                                                 }
> > >                                                 return null;
> > >                                         }
>
> > >                                         @Override
> > >                                         protected void 
> > > onProgressUpdate(Object... values) {
> > >                                                 
> > > super.onProgressUpdate(values);
> > >                                                 Integer progress = 
> > > (Integer)values[0];
> > >                                                 
> > > progressDialog.setProgress(progress.intValue());
> > >                                         }
>
> > >                                         @Override
> > >                                         protected void 
> > > onPostExecute(Object result) {
> > >                                                 
> > > super.onPostExecute(result);
> > >                                                 
> > > Enter.this.dismissDialog(PROGRESS_DIALOG_ID);
> > >                                         }
> > >                                 }.execute((Object[]) null);
> > >                         }
> > >         });
> > >     }
>
> > >     @Override
> > >     protected Dialog onCreateDialog(int id) {
> > >         Dialog dialog = null;
> > >         if (id == PROGRESS_DIALOG_ID){
> > >             progressDialog = new ProgressDialog(this);
>
> > > progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
> > >             progressDialog.setTitle("Pleae Wait");
> > >             progressDialog.setMessage("Running a long process...");
> > >             progressDialog.setCancelable(true);
> > >             dialog = progressDialog;
> > >         }
> > >         return dialog;
> > >     }
>
> > > Thanks!
>
> > > -Aaron
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to android-developers@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > android-developers+unsubscr...@googlegroups.com
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/android-developers?hl=en
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group 
> > athttp://groups.google.com/group/android-developers?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to