Fragments
Understanding fragments and their lifecycle
Introduction to Fragments
Fragments Android app development का एक महत्वपूर्ण component है। यह एक modular section होता है जो activity का एक part होता है और अपना own lifecycle रखता है।
Fragments are an important component in Android app development. They are modular sections that are part of an activity and have their own lifecycle.
Key Features (मुख्य विशेषताएं):
- Fragments reusable UI components होते हैं
- Fragments are reusable UI components
- एक activity में multiple fragments हो सकते हैं
- Multiple fragments can exist in one activity
- Fragments का अपना lifecycle होता है
- Fragments have their own lifecycle
- Fragments को runtime में add, remove, या replace किया जा सकता है
- Fragments can be added, removed, or replaced at runtime
Fragment Lifecycle (फ्रैगमेंट लाइफसाइकल)
Fragment का lifecycle activity के lifecycle से related होता है:
Fragment lifecycle is related to the activity lifecycle:
Implementation Example (इम्प्लीमेंटेशन उदाहरण)
Fragment को implement करने का example:
Example of implementing a fragment:
class MyFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_my, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Initialize views and setup UI
}
override fun onPause() {
super.onPause()
// Save fragment state
}
}
Fragment Communication (फ्रैगमेंट कम्युनिकेशन)
Fragments के बीच communication के तरीके:
Ways to communicate between fragments:
Best Practices (सर्वोत्तम प्रथाएं)
Fragments के साथ काम करने के best practices:
Best practices for working with fragments: