

My app is like the doc-example news reader. I used multiple-activity approach until I stepped into a problem. Thank you for this question and your insights. : NewsActivity1, NewsActivity2, NewsActivit圓 Here's how I imagine your application project could be setup: Sorry for the wordy reply! Perhaps you could tell more about your specific use case? Hope this helps! Not that the second doesn't have a time and place, but I could see the implementation getting messy quick!

I've usually employed the "multiple Fragment approach" for tablet versions of applications and a "one Fragment per Activity" for phones, which sounds in-line with your first approach listed. Just remember that if you find yourself doing it a lot, maybe a separate Activity is a more appropriate solution If its "natural" for you application to swap-out fragments, go for it.

This is not ideal, but it is the best I could come up with.īased on the suggestion by in the comments, there is a much cleaner way to handle back-button presses: Simply add to the Fragment backstack, the transaction of showing/hiding the details fragment. This means hiding it and showing the TitlesListFragment.

HOPE FRAGMENTS MEANING CODE
Then, in the code it is a matter of getResources().getBoolean(R.bool.dual_pane) I can then place additional config.xml files in folders like values-xlarge-land, values-port or values-sw600dp etc and adjust the boolean value to true or false as I desire. For example, I have a config.xml as follows: The one I prefer is to create a boolean resource. There are better ways to designate dual pane-ness than having a dummy view. MDualPane = findViewById(R.id.dualPane)!=null I hacked this by including a View with id dualPane and android:visibility="gone" in those layouts that I want to be dual-pane and omitting this view in the single-pane layout. However, in my solution, both fragments are always present in all layouts. We figure out whether we are currently in a dual-pane layout by testing for the existence of this Frame Layout. In the original News Reader example, dual-pane layouts have a FrameLayout for holding the news Details. Depending on the current dual-pane-ness, I show/hide the appropriate fragment.ĭesignating a Layout as Dual-pane or not: Both fragments are always present in NewsActivity.Two Fragments: TitlesListFragment and DetailsFragment.I hope to post my entire project shortly, but here is a quick overview of how I went about it: Also, I haven't looked in detail about the 3-pane scenario described in Edit 1 of my question. What remains to be seen is what are the use cases where this approach is preferable over the multiple-activity method (or whether there are any such cases at all).
HOPE FRAGMENTS MEANING ANDROID
I set out to modify the News Reader example from the Android developer guide to use the single-activity approach and came up with a workable solution. However, it wasn't an actual sharing of experience with using the single-activity approach as I asked in my original question. This answer by Clark was pretty informative.
