Activities & Fragments
An Activity represents a single screen in an Android app. Every activity goes through a well-defined lifecycle that helps Android manage memory and resources efficiently.
Search
An Activity represents a single screen in an Android app. Every activity goes through a well-defined lifecycle that helps Android manage memory and resources efficiently.
Key lifecycle states
🔸 onCreate() – Called when the activity is first created; initialize UI and data
🔸 onStart() – Activity becomes visible to the user
🔸 onResume() – Activity is in the foreground and user can interact
🔸 onPause() – Activity partially hidden; pause animations or save small data
🔸 onStop() – Activity no longer visible
🔸 onDestroy() – Activity is destroyed; clean up resources
Why lifecycle matters
🔸 Prevents memory leaks
🔸 Helps save and restore user data
🔸 Ensures smooth app performance
Intents (Explicit & Implicit)
An Intent is a messaging object used to request an action from another app component.
Explicit Intent
🔸 Used to start a specific activity within your app
🔸 You clearly mention the target class
🔸 Commonly used for internal navigation
Implicit Intent
🔸 Does not specify the target component
🔸 Android decides which app can handle the request
🔸 Used for actions like opening a browser, camera, or sharing content
Why intents are important
🔸 Enable communication between app components
🔸 Allow interaction with other apps
🔸 Support modular and flexible app design
Fragments & Fragment Manager
A Fragment is a reusable portion of UI inside an activity. One activity can host multiple fragments.
Fragments
🔸 Have their own lifecycle
🔸 Can be added, removed, or replaced dynamically
🔸 Improve UI flexibility for different screen sizes
Fragment Manager
🔸 Manages fragment transactions
🔸 Handles add, replace, remove operations
🔸 Maintains fragment back stack for navigation
Advantages of fragments
🔸 Better tablet and multi-pane layouts
🔸 Cleaner and reusable UI components
🔸 Easier UI updates without restarting activities
Bottom Navigation
Bottom Navigation allows switching between top-level views using tabs at the bottom of the screen.
Key features
🔸 Displays 3–5 primary destinations
🔸 Each tab represents an independent screen
🔸 Works best with fragments
When to use
🔸 Apps with multiple main sections
🔸 Quick and intuitive navigation
🔸 Modern material design apps
ViewPager
ViewPager allows users to swipe left or right between different screens or fragments.
Main concepts
🔸 Uses fragments as pages
🔸 Supports swipe gestures
🔸 Often combined with TabLayout
Common use cases
🔸 Intro/onboarding screens
🔸 Image sliders
🔸 Tab-based navigation
Benefits
🔸 Smooth user experience
🔸 Gesture-based navigation
🔸 Clean separation of content
Get the latest news right in your inbox. We never spam!
Comments