Activities and Fragments

  1. What is an Activity in Android?

    • An Activity represents a single screen with a user interface. It is a key component for creating the user interface and handling user interactions.
  2. What is the difference between an explicit and implicit Intent?

    • An explicit Intent specifies the component (e.g., Activity) to start, while an implicit Intent describes an action to perform, allowing the system to choose an appropriate component.
  3. Explain the purpose of the onActivityResult() method.

    • onActivityResult() is used to receive results from child activities started with startActivityForResult(). It’s essential for communication between activities.
  4. What is a Fragment in Android, and why is it used?

    • A Fragment is a modular component that can be combined to create more complex user interfaces within an Activity. It promotes reusability and flexibility.
  5. What is a back stack in Android, and how does it work?

    • The back stack is a collection of activities on the device, allowing users to navigate backward through the history of activities. The back stack is managed by the Android system.
  6. Explain the differences between onCreate(), onStart(), and onResume() methods in an Android Activity.

    • onCreate() is called when the activity is first created, onStart() is called when the activity becomes visible, and onResume() is called when the activity is at the forefront.
  7. How can you pass data between Fragments and Activities in Android?

    • You can pass data between Fragments and Activities using Bundle objects or interfaces. Additionally, you can use ViewModels to share data between them.