Reputation: 18583
Why does the log-line yield "true" here? I just added a fragment with tag "ID"!
FragmentTransaction ftrans = getSupportFragmentManager().beginTransaction();
ftrans.add(0, new MyFrag(), "ID");
ftrans.commit();
Fragment frag = getSupportFragmentManager().findFragmentByTag("ID");
Log.i("", "Fragment is null? " + (frag == null));
Is there a delay on the commit? If so, is there any event I can listen for when the commit is completed?
Upvotes: 2
Views: 1332
Reputation: 36
public abstract int commit ()
Schedules a commit of this transaction. The commit does not happen immediately; it will be scheduled as work on the main thread to be done the next time that thread is ready.
You can try adding fragmentManager.executePendingTransactions() after your commit() and before finding your tag.
Upvotes: 2