FragmentTransaction.detach(Fragment fragment)

4,473 views
Skip to first unread message

Ralph Bergmann | the4thFloor.eu

unread,
Sep 9, 2011, 6:47:12 AM9/9/11
to android-...@googlegroups.com
Hello,


what should happen when I call FragmentTransaction.detach(Fragment
fragment)? Should the Fragment.onDetach() method be called or not?

I have played with this example:
http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.html

At the end of this file you find the "public void onTabChanged(String
tabId)" method with this line "ft.detach(mLastTab.fragment);".

But when this ft.detach is called, the Fragment.onDetach() is not called :-(

Is it right? Or wrong?

I think it is wrong.

The ft.detach method calls "FragmentManager.detachFragment(Fragment
fragment, int transition, int transitionStyle)" (line 1158 @
http://code.google.com/p/openintents/source/browse/trunk/compatibility/AndroidSupportV2/src/android/support/v2/app/FragmentManager.java)

But the FragmentManager sets only a flag that the Fragment was detached
(line 1161). But the fragment was not notified with a method call.

Ralph

Dianne Hackborn

unread,
Sep 9, 2011, 12:39:07 PM9/9/11
to android-...@googlegroups.com
No, it's a little unfortunately naming.  onDetach() means detached from the activity.  Your fragment is still attached to the activity.  FragmentManager.detach() essentially puts it into the same state as when it is pushed on the fragment back stack.


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




--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Ralph Bergmann | the4thFloor.eu

unread,
Sep 9, 2011, 1:38:22 PM9/9/11
to android-...@googlegroups.com
Am 09.09.11 18:39, schrieb Dianne Hackborn:

> No, it's a little unfortunately naming. onDetach() means detached
> from the activity. Your fragment is still attached to the activity.
> FragmentManager.detach() essentially puts it into the same state as
> when it is pushed on the fragment back stack.

But when "ft.detach(mLastTab.fragment);" is called the fragments variable

// Set to true when the app has requested that this fragment be deactivated.
boolean mDetached;

is set to true.

Why is onDetach() not also called? The internal state is mDetached =
true but nobody is notified about this state change.


Ralph

--

Ralph Bergmann

iOS and Android app developer


www http://www.the4thFloor.eu | http://www.dasralph.de

mail ra...@the4thFloor.eu
skype dasralph

xing http://www.xing.com/profile/Ralph_Bergmann3
gulp http://www.gulp.de/Profil/RalphBergmann.html
linkedin http://www.linkedin.com/in/ralphbergmann

java user group http://www.jug-bb.de | http://www.xing.com/net/jugbb
ios dev group http://www.xing.com/net/iosberlin


pgp key id BED003DD883B9A80
pgp fingerprint 7865 EAD3 5834 705B D8B7 AD7C BED0 03DD 883B 9A80

Dianne Hackborn

unread,
Sep 9, 2011, 2:11:19 PM9/9/11
to android-...@googlegroups.com
Like I said, onDetach() means it is completely detached from the activity.  Sorry for the poor naming here, they are just different things.


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

Reply all
Reply to author
Forward
0 new messages