简体   繁体   中英

Fragment switching or Multiple activities?

I have a two pane master-detail style application with differing views for the tablet and phone version. Is it recommended to have a single activity switching fragments in the phone layout or is it better practice to have two activities, one with each fragment? The android examples have both ways implemented but i am not sure which is the best practice and why?

Afaik, the example of dual pane showed in the official documentation specifies 2 fragments and 2 activities, but this isn't a choice you have to do. Both are required.

  • For phones, activity A shows fragment #1 and activity B shows fragment #2.
  • For tablets, activity A shows both fragment #1 and #2, and activity B isn't used.

I use fragments for this. On a phone, there's a viewpager which lets the user switch between fragments. On a tablet, fragments are shown at the same time. But of course, it all depends on what your app does.

Depending on your app and on the users, you can have a tab bar that lets users switch the viewpager.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM