I've taken care of the dialog's on rotation issue with a custom
pattern.  I posted it here a few months ago, but was shut down by
people.  It's not that simple, but it works very well and the dialogs
are preserved perfectly.  If you care, I can post my solution again.



On Jun 20, 1:08 pm, William Ferguson <[email protected]>
wrote:
> Android doesn't handle rotation and dialogs particularly well, mainly
> due to rotation causing the Activity to be destroyed and a new one
> created. This leaves Dialogs with an invalid Context. Using managed
> dialogs (like you are) just shifts the problem, otherwise you get
> java.lang.IllegalArgumentException: View not attached to window
> manager instead.
>
> In Froyo and below calling dismissDialog for an Activity that has
> already been destroyed causes the Exception you noted. As far as I can
> recall, Gingerbread logs a message but swallows the Exception. I have
> tended to add a try/catch around dismissDialog to handle the pre
> Gingerbread cases.
>
> You can configure your Activity to stop rotation occurring, or your
> can code your Activity to handle rotation.
> But as Streets of Boston says, you don't want to be firing off your
> AsyncTask in onCreate, at least not without checking to see whether
> this Activity has already been started/destroyed due to rotation. See
> #getLastNonConfigurationInstance.
>
> On Jun 20, 1:52 pm, sahana uday <[email protected]> wrote:
>
>
>
> > Hi,
> > I understood what you were trying to say. Here's what I;'m doing now:
>
> > class ConnectionsListAddScreen extends Activity{
> >        public void onCreate(Bundle savedInstState){
> >             super.onCreate(savedInstState);
> >             //here on particular button click
> >             new ConnReqSenderAsyncTask().execute();
>
> >        }
>
> >        protected Dialog onCreateDialog(int id) {
> >                 Dialog dialog = new Dialog(ConnectionsListAddScreen.this);
> >                 switch(id){
> >                         case Constants.LOGIN_DIALOG:    ProgressDialog pg = 
> > new
> > ProgressDialog(ConnectionsListAddScreen.this);
> >                                                         
> > pg.setMessage(//some string);
> >                                                         
> > pg.setCancelable(true);
> >                                                         dialog = pg;
> >                                                         break;
> >                         default:        return super.onCreateDialog(id);
>
> >                 }
> >                 return dialog;
> >         }
>
> > }
>
> > private class ConnReqSenderAsyncTask extends
> > AsyncTask<Void,Void,Void>{
>
> >         protected Void doInBackground(Void... params) {
> >               //send request to server
> >               return null;
> >         }
>
> >         protected void onPreExecute() {
> >                 super.onPreExecute();
> >                 showDialog(Constants.LOGIN_DIALOG);
> >         }
>
> >         protected void onPostExecute(Void result) {
> >                 super.onPostExecute(result);
> >                 dismissDialog(Constants.LOGIN_DIALOG);
> >         }
>
> > }
>
> > If the above is right. Then the problem is on Orientation Change it
> > throws below exception:
>
> > FATAL EXCEPTION: main
> > java.lang.IllegalArgumentException: no dialog with id 5 was ever shown
> > via Activity#showDialog
> > at android.app.Activity.missingDialog(Activity.java:2590)
> > at android.app.Activity.dismissDialog(Activity.java:2575)
> > at com.sap.explorer.view.ConnectionsListAddScreen
> > $ConnReqSenderAsyncTask.onPostExecute(ConnectionsListAddScreen.java:
> > 699)
> > at com.sap.explorer.view.ConnectionsListAddScreen
> > $ConnReqSenderAsyncTask.onPostExecute(ConnectionsListAddScreen.java:1)
> > at android.os.AsyncTask.finish(AsyncTask.java:417)
> > at android.os.AsyncTask.access$300(AsyncTask.java:127)
> > at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:
> > 429)
> > at android.os.Handler.dispatchMessage(Handler.java:99)
> > at android.os.Looper.loop(Looper.java:123)
> > at android.app.ActivityThread.main(ActivityThread.java:4627)
> > at java.lang.reflect.Method.invokeNative(Native Method)
> > at java.lang.reflect.Method.invoke(Method.java:521)
> > at com.android.internal.os.ZygoteInit
> > $MethodAndArgsCaller.run(ZygoteInit.java:868)
> > at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
>
> > Since we are using showDialog(...) and onCreateDialog(...) for
> > ProgressDialog display, then shouldn't Android keep a reference of
> > same on orientation change. Can you let me know if there are any
> > mistakes in my code or solution to my problem asap.
>
> > On Jun 16, 4:02 pm, sahana uday <[email protected]> wrote:
>
> > > Hi,
> > > Yes I'm sending the request to server in onCreateDialog(), but its an
> > > AsyncTask.
> > > In onPreExecute() show theprogressdialogand onPostExecute() cancel
> > > theprogressdialog.
>
> > > Off late I have anotherissuein computing textview height, I have
> > > posted thisissueon a separate thread also.
> > > The issues is:
> > >         How to compute TextView Height before its laid out on screen?
>
> > >         I'm not aware how we can use getPaint().ascent() or descent()
> > > method
> > >         for computing height?
>
> > >         Can you please provide an example
>
> > > On Jun 6, 6:38 pm, Streets Of Boston <[email protected]> wrote:
>
> > > > Are you sending a request to the server in the implementation of the
> > > > 'onCreateDialog(...)' method? If so, this is not good. The 
> > > > onCreateDialog is
> > > > called by the OS when the hosting activity is recreated due to a config
> > > >changewhen adialogis shown using the showDialog method (i.e. an
> > > > activity-manageddialog). This is perfectly normal behavior.
>
> > > > Call 'showDialog' just *after *you send an (asynchronous) request to the
> > > > server and call 'dismissDialog' when the server returns a response. 
> > > > Usually,
> > > > do not code anything in the onCreateDialog except for building an
> > > > AlertDialog object.- Hide quoted text -
>
> - Show quoted text -

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

Reply via email to