but I'm not adding twice the same fragment in one fragment
transaction.
here is what happens :
1) launch app
=> call to "onTabSelected" => add my fragment with this piece of
code:
if(!fragmentsToAdd.isAdded())
ft.add( R.id.parent, fragmentsToAdd, "myFragment");
2) pressing the Back button
=> we are leaving the app (I guess in 'pause' state)
3) launching my app again
=> new call to "onTabSelected"
=> myfragment.isAdded() return false whereas I already added it
once.
( because mActivity = null in myfragment and I don't understand why)
=> IllegalStateException: Fragment already added
why des mActivity is null a this step ? is the fragment automaticly
destroyed or removed when pausing/stoping the app ?
On 22 juil, 02:44, Dianne Hackborn <[email protected]> wrote:
> Committing a fragment is asynchronous; isAdded() doesn't return true until
> the transaction is committed.
>
>
>
>
>
>
>
>
>
> On Thu, Jul 21, 2011 at 9:33 AM, Gab <[email protected]> wrote:
> > I have a same problem, my fragment lost the reference of activity
> > after pause/resume...
> > I don't understand the fragment's lifecycle.
>
> > On 19 juil, 15:10, Guian <[email protected]> wrote:
> > > well well ...
>
> > > here is the fix I used :
>
> > > on the creation of my fragment I add a test in fragment.getActivity()
> > > is null ...
>
> > > if(testFragment == null || testFragment.getActivity()==null)
> > > testFragment = (TestFragment) TestFragment.instantiate(context,
> > > "com.mypackage.test.MyFragment");
>
> > > and I recreate a previously build fragment which I think isn't very
> > > optimised ...
>
> > > any comment/advise on this is welcome.
>
> > > On 19 juil, 14:31, Guian <[email protected]> wrote:
>
> > > > here is the source code forisAdded:
>
> > > > /**
> > > > * Return true if the fragment is currently added to its activity.
> > > > */
> > > > final public booleanisAdded() {
> > > > return mActivity != null && mAdded;
> > > > }
>
> > > > indeed ... mActivity is null...
>
> > > > I guess I have to recreate this fragment from scratch since I've lost
> > > > its activity owner ?
> > > > what cause this reference on mActivity being lost ?
> > > > if its the onPause => onResume, what's the point of having a onPause
> > > > onResume methods to implement in Fragment, if we have to recreate it
> > > > anyway ?
>
> > > > On 19 juil, 12:23, Guian <[email protected]> wrote:
>
> > > > > I've seen thatisAdded() can return false even if the field 'mAdded'
> > > > > in the Fragment is true ?
> > > > > (seen in the 'Variables' view in eclipse )
>
> > > > > does anybody know why ?
>
> > > > > On 19 juil, 11:46, Guian <[email protected]> wrote:
>
> > > > > > I can't understand how this piece of code :
>
> > > > > > if(!fragmentsToAdd.isAdded())
> > > > > > ft.add( R.id.parent, fragmentsToAdd, "myFragment");
>
> > > > > > can lead to this exeption :
>
> > > > > > FATAL EXCEPTION: main
> > > > > > java.lang.IllegalStateException: Fragment already added:
> > > > > > TestFragment{40856358 #0 id=0x7f060024 "myFragment"}
> > > > > > at android.app.BackStackRecord.doAddOp(BackStackRecord.java:322)
> > > > > > at android.app.BackStackRecord.add(BackStackRecord.java:316)
> > > > > > at com.mypackage.test.MyActivity.onTabSelected(MyActivity.java:164)
>
> > > > > > does the isAdded() function works fine ?
>
> > > > > > ( used with android 3.1, it happens when leaving the app in pause
> > > > > > state, then resume it and change Tab from the action bar. )
>
> > > > > > any cu
>
> > --
> > 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
>
> --
> Dianne Hackborn
> Android framework engineer
> [email protected]
>
> 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.
--
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