Q1. Explain the lifecycle of an Android Activity or an iOS ViewController. What are common pitfalls and how do you mitigate them?
Why you'll be asked this: This question assesses your foundational understanding of the respective mobile operating system's core components and how to manage their states effectively, crucial for preventing crashes and memory leaks.
Start by outlining the key lifecycle states (e.g., for Android: onCreate, onStart, onResume, onPause, onStop, onDestroy; for iOS: viewDidLoad, viewWillAppear, viewDidAppear, viewWillDisappear, viewDidDisappear, deinit). Describe what typically happens in each state. Then, discuss common pitfalls such as memory leaks (e.g., strong reference cycles in iOS, holding context references in Android), incorrect data persistence, or UI updates on background threads. Explain mitigation strategies like using weak references, proper data saving/restoration, and ensuring UI updates occur on the main thread.
- Incomplete or inaccurate description of lifecycle states.
- Inability to identify common pitfalls or provide practical mitigation strategies.
- Lack of distinction between main and background thread operations.
- How do you handle configuration changes (e.g., screen rotation) in Android or memory warnings in iOS?
- When would you use a Fragment over an Activity, or a custom View over a ViewController?
- How do you ensure data is not lost if the app is terminated unexpectedly?