Answer: C An activity can contain multiple fragments in it.
Description:
Answer: C fragments will be moved to onStop
Description: Since fragments are part of an Activity always, when Activity is moved to stopped state, then automatically fragments in it will be moved to stopped state.
Note: Fragments life cycle will be affected by activity's life cycle.
Answer: D i, ii, & iv
Description: Fragments is a new concept introduced in 3.0 version.
The basic purpose of fragments is:
1. Fragments are designed to use the device UI space efficiently.
When you are writing an application in android, then some people can download it into phone, some into tablets. If you see the space in tablets it will be little bigger than phones. You should be able to use that space efficiently. But you can't keep writing different applications one targeting for phone, and other targeting for tablets. In order to do it efficiently, i.e writing only application that can fit well with all screen sizes, we use fragments concept.
2. fragments are designed as a reusable UI components between more than one activity.
Once you design a fragment, you can view it as a detachable independent unit, so that you can plug it into any activity where ever there is a space. That means you can reuse the code designed for a fragment.
Fragment you can think of it like a sub activity, which sits with in an activity and which contributes its own UI to the activity screen.
Fragments are always part of an activity. With out an activity, a fragment will not exist. So your fragment life cycle will always be affected by activity life cycle.
An activity can contain more than one fragment. Similarly a fragment can be re used in multiple activities.
Answer: B FragmentManager.findFragmentById(R.id.frag_id);
Description: To find if a fragment is part of an activity or not, we have to take the help of FragmentManager and use findFragmentById() function.
Answer: D use layout-port folder for portrait mode, and layout folder for landscape mode.
Description: Create two different xml layout files with same name, put one under res/layout-port folder and other under res/layout folder.
Android will automatically pick layout-port folder xml file for portrait mode, and other for landscape mode.
Answer: B onCreateView()
Description: We have to implement onCreateView() to return the layout of fragment as part of fragments UI contribution.
Answer: B Fragment generally will contribute its UI by using its own layout. But it might not have UI in some cases, as it is not mandatory.
Description: Fragment generally will contribute its UI by using its own layout. But it might not have one in some cases.
Answer: B use activity & a ListFragment
Description: If a fragment is required to display a list view in it, then there is special purpose fragment called as ListFragment to achieve it.
So use activity with ListFragment.
Answer: D ActivityFragment
Description: There is nothing called as ActivityFragment class. Remaining are derived classes of Fragment class.
Answer: C onActivityDestroyed()
Description: onActivityDestroyed() is not the part of Fragment life cycle.
Answer: D onAttach()
onCreate()
onCreateView()
onActivityCreated()
onStart()
onResume()
Description:
Answer: C Y must use fragment- transaction with fragment-manager and replace itself with screen Z.
Description:
Answer: D all are true
Description:
Answer: D all are true
Description:
Answer: D all are true
Description: