A Fragment is a piece of an activity which empower more measured activity design. It won't be right in the event that we say, a fragment is a sort of sub-activity.
Following are significant focuses about fragment −
A fragment has its own design and its own conduct with its own life cycle callbacks.
You can add or eliminate fragments in an activity while the activity is running.
You can join various fragments in a solitary activity to construct a multi-sheet UI.
A fragment can be utilized in various activities.
Fragment life cycle is firmly identified with the existence pattern of its host activity which implies when the activity is stopped, every one of the fragments accessible in the activity will likewise be halted.
A fragment can execute a conduct that has no UI segment.
Fragments were added to the Android API in Honeycomb version of Android which API version 11.
You make fragments by broadening Fragment class and You can embed a fragment into your activity format by announcing the fragment in the activity's design document, as a <fragment> component.
Preceding fragment presentation, we had a constraint since we can show just a solitary activity on the screen at one given point on schedule. So we couldn't partition gadget screen and control various parts independently. In any case, with the presentation of fragment we got greater adaptability and eliminated the limit of having a solitary activity on the screen at a time. Presently we can have a solitary activity yet every activity can contain numerous fragments which will have their own format, occasions and complete life cycle.
Following is a run of the mill illustration of how two UI modules characterized by fragments can be joined into one activity for a tablet design, however isolated for a handset design.
The application can implant two fragments in Activity A, when running on a tablet-sized gadget. Be that as it may, on a handset-sized screen, there's not adequate space for the two fragments, so Activity An incorporates just the fragment for the rundown of articles, and when the client chooses an article, it begins Activity B, which incorporates the subsequent fragment to peruse the article.
0 Comments