Junior
What is an Activity in Android and what is it used for?
sobes.tech AI
Answer from AI
Activity is a fundamental building block of an Android application, representing a single screen with a user interface.
Main functions and purpose:
- User Interface: Displays visual elements (Layout) and interacts with the user.
- Lifecycle: Managed by the Android system and has a set of states (creation, start, pause, stop, destroy).
- Navigation: Allows transitioning between different screens of the application.
- Event Handling: Responds to user actions and system events.
Example of creating a simple Activity:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) // Binding to layout
}
}