[android-developers] When to show a dialog from Fragment and when not to

2013-04-14 Thread William Ferguson
I have a Fragment that fires an async task to connect to a remote server. 
If it fails to connect (eg times out) then I use use a Handler to display a 
dialog to the user.

final DialogFragment newFragment = 
> AlertDialogFragment.createConnectionFailedDialog(getSupportActivity());
> newFragment.show(getFragmentManager());


All good except that the async task if the user navigates away from the 
Activity hosting that Fragment (eg goes to Preferences) then when the time 
out occurs the Fragment is in a quasi shut down state and the following 
exception is thrown.

04-14 23:11:51.407: ERROR/AndroidRuntime(6267): FATAL EXCEPTION: main
> java.lang.IllegalStateException: Can not perform this action after 
> onSaveInstanceState
> at 
> android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1327)
> at 
> android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1338)
> at 
> android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
> at 
> android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
> at 
> org.holoeverywhere.app.DialogFragment.show(DialogFragment.java:369)
> at 
> org.holoeverywhere.app.DialogFragment.show(DialogFragment.java:350)
> at 
> org.holoeverywhere.app.DialogFragment.show(DialogFragment.java:329)
> at 
> au.com.xandar.wirelesstiming.connection.ConnectionFragment.updateUserInterfaceOnClose(ConnectionFragment.java:197)
> at 
> au.com.xandar.wirelesstiming.connection.ConnectionFragment.access$200(ConnectionFragment.java:26)
> at 
> au.com.xandar.wirelesstiming.connection.ConnectionFragment$2.run(ConnectionFragment.java:96)
> at android.os.Handler.handleCallback(Handler.java:725)
> at android.os.Handler.dispatchMessage(Handler.java:92)
> at android.os.Looper.loop(Looper.java:137)
> at android.app.ActivityThread.main(ActivityThread.java:5041)
> at java.lang.reflect.Method.invokeNative(Native Method)
> at java.lang.reflect.Method.invoke(Method.java:511)
> at 
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
> at dalvik.system.NativeStart.main(Native Method)


What is the correct way to handle this scenario?

Ideally I'd like to always display the dialog, but if that is not an 
option, then what do I use to determine whether the dialog should be 
displayed or not?


William 

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [android-developers] When to show a dialog from Fragment and when not to

2013-04-14 Thread Harri Smått
Hi,

You could try using Fragment.isVisible() to determine whether the fragment is 
visible and can trigger a dialog. For situations where fragment is in the 
background you could use a Toast perhaps?

--
H

On Apr 14, 2013, at 4:25 PM, William Ferguson  
wrote:

> I have a Fragment that fires an async task to connect to a remote server. If 
> it fails to connect (eg times out) then I use use a Handler to display a 
> dialog to the user.
> 
> final DialogFragment newFragment = 
> AlertDialogFragment.createConnectionFailedDialog(getSupportActivity());
> newFragment.show(getFragmentManager());

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [android-developers] When to show a dialog from Fragment and when not to

2013-04-15 Thread William Ferguson
Fragment#isVisible is returning true even if the user has navigated to 
another Activity. However #isResumed returns false, so maybe that is the 
right target.

On Sunday, April 14, 2013 11:42:06 PM UTC+10, Harri Smått wrote:
>
> Hi, 
>
> You could try using Fragment.isVisible() to determine whether the fragment 
> is visible and can trigger a dialog. For situations where fragment is in 
> the background you could use a Toast perhaps? 
>
> -- 
> H 
>
> On Apr 14, 2013, at 4:25 PM, William Ferguson 
> > 
> wrote: 
>
> > I have a Fragment that fires an async task to connect to a remote 
> server. If it fails to connect (eg times out) then I use use a Handler to 
> display a dialog to the user. 
> > 
> > final DialogFragment newFragment = 
> AlertDialogFragment.createConnectionFailedDialog(getSupportActivity()); 
> > newFragment.show(getFragmentManager()); 
>
>

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.