Hi,
we're migrating a project to Fragments support, because we support both,
tablets and smartphones now. I'm familiar with Fragments already, but there
is an unanswered question for which I already searched for an answer - for
now without luck:
Please have a look at the following code sample, especially the else block:
public void showDetails(int index) {
Log.v(TAG, "in MainActivity showDetails(" + index + ")");
if (isMultiPane()) {
// Check what fragment is shown, replace if needed.
DetailsFragment details = (DetailsFragment)
getFragmentManager().findFragmentById(R.id.details);
if ((details == null) ||
(details.getShownIndex() != index)) {
// Make new fragment to show this selection.
details = DetailsFragment.newInstance(index);
// Execute a transaction, replacing any existing
// fragment with this one inside the frame.
Log.v(TAG, "about to run FragmentTransaction...");
FragmentTransaction ft =
getFragmentManager().beginTransaction();
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
//ft.addToBackStack("details");
ft.replace(R.id.details, details);
ft.commit();
}
} else {
// Otherwise you need to launch a new activity to display
// the dialog fragment with selected text.
Intent intent = new Intent();
intent.setClass(this, DetailsActivity.class);
intent.putExtra("index", index);
startActivity(intent);
}
}
Unclear to me: why do we start the Fragment within a new Activity instead
adding it to the fragment stack?
I think it's because Fragments started with Android 3.0 where Fragments was
firtly introduced to tablets!? But I can't find explanations for this
behavior.
Now I beleave it is better to handle them as Fragments on single pane too.
Can someone agree please.
What is the (more) correct (more official/ suggested) way? We're developing
for Android 4.0+.
Thanks for answering.
Danny Schimke
--
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
---
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 [email protected].
For more options, visit https://groups.google.com/d/optout.