android - Two panel UI with Fragments vs Separate activities -


I am starting a Honeycomb application with a basic two panel layout, one panel on the left and one for each menu Right to the main functionality of the section

Unlike the available samples of Fragments API, the content displayed on the right panel is a completely different UI for each menu option.

It is enticing to change the right piece according to the selected section, but it means to use only one activity in the whole app, and it does not look good. Apart from this, the life cycle of the piece is tied to the activity, so no piece will be killed until the activity is killed, resulting in many pieces being "alive".

However, having a different activity with two panels for each menu option means that the piece used for the menu must be added to each activity and subject to the incompatible layout in all those sections Should be a menu

What are the best practices here?

The blog post summarizes the reasons for choosing pieces of activity:

Embedded activities through activity groups were a good idea, but it has been difficult to deal with always because instead of interacting with other activities closely with the other activities, an independent self-reliant component has been created. Fragment APIs are a better solution for this, and they should be treated as the replacement of embedded activities.

Maintaining data in the examples of activity can be accomplished through activity. Then Sanon Configuration (Instance), but it is quite Calcutta non-obvious. The piece changes the mechanism, so that you can set a flag to maintain an entire piece of the example.

The dialogue with a special dialog called Fragment makes it easy to show an activity that is managed as part of the activity life cycle. This activity changes the managed dialog that API changes.

Another specialization of the fragmentation, called a catalog program, makes it easy to show a list of data. This is similar to the existing ListActivity (with some other features), but this should reduce the general question about how A & gt; List with some other data

At present, information about all the pieces associated with any activity is saved for you by the structure in the event situation saved for you and restored to you if it is restarted. It can greatly reduce the amount of state to save and restore codes that you need to write.

Framework has built-in support for managing the back-stack of fragment objects, making it easy to provide inter-activity back button behavior that integrates the current activity into the stack. This situation is automatically saved and restored to you.

The pieces are quite new, so beyond that article, I'm not sure that you are going to find a lot for the best practices. I think the decision you need to make is that my conversation is tightly coupled and the data is shared or they stand alone, who do not make much contact.


Edit, Explanation : I think the use of the same activity for the app is not necessarily a wrong decision. This is actually a decision based on the functionality of your app. Depending on the article, an activity is standing alone, whereas a piece is usually relevant only in association with other pieces in the scope of an activity. The situation you describe, with the combination of different activities, is one of the pain points which they have been prepared to solve.

Comments