简体   繁体   中英

How to use activities or fragments in a multi screen workflow?

I have a workflow with several screens with different questions and answer-options. So there is a question on screen 1 and the user makes his choise -> the user hits the continue button -> screen 2 opens with another question -> user makes his choice and continues -> screen 3 opens etc...

But actually I'm not sure which is the best way to implement this behavior in consideration of a good maintainability and clearness. I think they are at least three options:

  1. Every screen gets its own activity and layout file and I pass the choosen data trough intents.

  2. 1 Activity and different fragments, each fragment has its own layout. If the continue button is pressed, the fragment will be replaced with the next fragment.

  3. 1 Activity and different layout files. Just the layout gets replaced and everything else is handled in the activity.

Actually I already started implementing with option 2.) but I don't know if this is not "too much".

The Android API guidelines say that you should use Fragments for multipane UI and for reusability . But actually I don't want to build a multipane UI in this case and the fragments are not reused. So maybe 3.) is the way to go? Or even 1.) ?

I would choose your option # 3. The reasons are:

  • Activity takes some memory compared to fragment or layouts. The interface between activities and fragments is a bit awkward, though I got used to it. I don't recommend it for your case.
  • I like fragments. However if all the fragments are similar in looks/feel, then why take the computer time for hiding/showing or replacing them. The reason for fragments is stated in Google web page like at Building a Flexible UI . I don't think you need a flexible UI as said in Google's intention.
  • I would suggest one Activity, at least one Fragment for all the questions/answers. You simply use one layout to change text/content. If the UI is different, then replace the layout with another. It's quite normal for an Android app to have so many different layouts anyway. Android takes some memory to load layouts but it's quite fast and efficient.

For option 3 design : You can use the inflate () method to load a certain layout and to replace one. A good example at SO link @ Android layout replacing a view with another view on run time

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