anandwana001 / android-interview

📚 Questions for Android Engineer Interview 📚
293 stars 64 forks source link
android android-compose hacktoberfest interview interview-questions java kotlin questions system-design

Android Engineer Interview Questions

Android Kotlin

Let's Learn for Free! Click Here

Book 1:1 Session here -> Click Here

Complete Android Engineer Roadmap

Interview Contents

Kotlin

Android

Lifecycle

Important Lifecycle Points to Remember

Opening a fragment from Activity

Code

supportFragmentManager.beginTransaction()
    .replace(R.id.fragment_container, FragmentA())
    .commit()
Callbacks
MainActivity onCreate
FragmentA onAttach
FragmentA onCreate
FragmentA onCreateView
FragmentA onViewCreated
FragmentA CREATED == Lifecycle.State
FragmentA onViewStateRestored
FragmentA onStart
FragmentA STARTED == Lifecycle.State
MainActivity onStart
MainActivity onResume
FragmentA onResume
FragmentA RESUMED == Lifecycle.State
MainActivity onAttachedToWindow

Adding a Fragment from a Fragment

Code

parentFragmentManager.beginTransaction()
    .add(R.id.fragment_container, FragmentB())
    .commit()
parentFragmentManager.beginTransaction()
    .add(R.id.fragment_container, FragmentB())
    .addToBackStack(null)
    .commit()
Callbacks
FragmentB onAttach
FragmentB onCreate
FragmentB onCreateView
FragmentB onViewCreated
FragmentB CREATED == Lifecycle.State
FragmentB onViewStateRestored
FragmentB onStart
FragmentB STARTED == Lifecycle.State
FragmentB onResume
FragmentB RESUMED == Lifecycle.State

Replacing a Fragment from a Fragment

Code

parentFragmentManager.beginTransaction()
    .replace(R.id.fragment_container, FragmentB())
    .addToBackStack(null)
    .commit()
Callbacks
FragmentA onPause
FragmentA onStop
FragmentB onAttach
FragmentB onCreate
FragmentB onCreateView
FragmentB onViewCreated
FragmentB CREATED == Lifecycle.State
FragmentB onViewStateRestored
FragmentB onStart
FragmentB STARTED == Lifecycle.State
FragmentA onDestroyView
FragmentB onResume
FragmentB RESUMED == Lifecycle.State

Code

parentFragmentManager.beginTransaction()
    .replace(R.id.fragment_container, FragmentB())
    .commit()
Callbacks
FragmentA onPause
FragmentA onStop
FragmentB onAttach
FragmentB onCreate
FragmentB onCreateView
FragmentB onViewCreated
FragmentB CREATED == Lifecycle.State
FragmentB onViewStateRestored
FragmentB onStart
FragmentB STARTED == Lifecycle.State
FragmentA onDestroyView
FragmentA onDestroy
FragmentA onDetach
FragmentB onResume
FragmentB RESUMED == Lifecycle.State

Coming Back to Previous Fragment after Adding

Note: If addToBackStack is not used, and back stack is empty, nothing will happen when calling popBackStack() function

Code

// FragmentA
parentFragmentManager.beginTransaction()
    .add(R.id.fragment_container, FragmentB())
    .addToBackStack(null)
    .commit()

// FragmentB
parentFragmentManager.popBackStack()
Callbacks
FragmentB onPause
FragmentB onStop
FragmentB onDestroyView
FragmentB onDestroy
FragmentB onDetach

FragmentA is visible. No FragmentA callbacks as FragmentA is always there, neither the view nor the lifecycle get affected.

Coming Back to Previous Fragment after Replacing

Note: If addToBackStack is not used, and back stack is empty, nothing will happen when calling popBackStack() function

Code

// FragmentA
parentFragmentManager.beginTransaction()
    .replace(R.id.fragment_container, FragmentB())
    .addToBackStack(null)
    .commit()

// FragmentB
parentFragmentManager.popBackStack()
Callbacks
FragmentB onPause
FragmentB onStop
FragmentA onCreateView
FragmentA onViewCreated
FragmentA CREATED == Lifecycle.State
FragmentA onViewStateRestored
FragmentA onStart
FragmentA STARTED == Lifecycle.State
FragmentB onDestroyView
FragmentB onDestroy
FragmentB onDetach
FragmentA onResume
FragmentA RESUMED == Lifecycle.State

FragmentA view is created again. When replacing, the FragmentA view gets destroyed, onDestroyView gets called so when coming back it calls onCreateView to initialise the view again. Though, onCreate will not get called again.

Lifecycle State

There are 5 States:

Points to Remember

States are based on Context/Scope you are using in. Example:

viewLifecycleOwner.lifecycleScope.launch {
    repeatOnLifecycle(Lifecycle.State.CREATED) {
        //...
    }
}
// viewLifecycleOwner => Lifecycle of the View
// should be used between onCreateView() and onDestroyView()
this.lifecycleScope.launch {
    repeatOnLifecycle(Lifecycle.State.CREATED) {
        //...
    }
}
// this => Lifecycle of Fragment or Activity
CREATED - listen in onDestroyView (if not View lifecycle) and in onStop, onSavedInstance too
STARTED - listen in onStart, onPause
RESUMED - listen in onResume
DESTROYED - listen in onDestroyView (if View lifecycle) and in onDestroy
CREATED - listen in onViewStateRestored (if View lifecycle)
CREATED - listen in onCreate, onCreateView, onViewCreated, onViewStateRestored (if not View lifecycle)

Examples

Networking

Webview

Dependency Injection

Jetpack Compose

Thread

Architecture

Design Pattern

System Design

Libraries

Common Question

Questions from Company

Company Questions
Booking.com
  • Implement findViewById method
  • Given a list of words as input, output another list of strings, each containing words that are mutual anagrams
  • Identify whether four sides (given by four integers) can form a square, a rectangle or neither
  • Output a delta encoding for the sequence. In a delta encoding, the first element is reproduced as-is. Each subsequent element is represented as the numeric difference from the element before it
  • Three integer arrays are given with duplicate numbers. Find the common elements among three arrays
  • Twisted question related to ConcurrentModificationException in an ArrayList
  • How do you implement a hotel list and detail screen? Discuss what all APIs You will create and how the layout will be
  • Fragments & their lifecycle, Activity lifecycle, Views, Layouts
  • Background task in Android - Asynctask, service, intent services, etc
  • Given dates and number of check-in and check-out on those dates. Find the busiest day in the hotel. [Merge Array interval type question]
  • Given an array, determine if there are repeated elements. If an element is repeated more than 3 times, return those elements. This question is basically doing a hash and checking if the hash already exists. Someone used a Map and a Set.
  • Given a list of positive words, negative words, and a review, determine if the review is flagged as positive, negative, or neutral. Someone solved it using a Set. Someone just needed to do some count (+ or -) regarding where the word appeared (positive list or negative).
Spotify
  • Design components and overall architecture for a Search feature in an Android application. [Spotify - Android Engineer II - London, UK - Sep 2022]
  • Design a Disk based Cache for the client. [Spotify System Design Android/iOS Client] Platform independent, Key will be 32 bytes, Value can be anything but in Byte array, Cache should be persistent, Cache should max hold 100k+ Objects, Cache Max size should be configurable ( Max Size: 10 MB upto 1GB), Cache should be opaque, Cache should be Secure
  • Linked List Cycle
  • Palindrome Linked List
PhonePe
  • Minimum Meetroom scheduling
  • Anagram Strings based question
Paytm
  • To check if strings are rotations of each other or not. If they are in rotation print the no. of rotations.
  • Find the string is anagram or not
  • Design components and overall architecture for a Search feature in an Android application
  • Sort an array of 0s, 1s and 2s
  • Abstract vs Interface
  • Android Memory related
Meesho
  • SOLID principles
  • Dagger, why use dependency injection, what if we do not think it is important, like alternatives? How to create our own dependency injection library.
  • why use MVVM over MVP, think outside the box, we could have used observables using RxJava, etc. - open-ended questions around it
  • Multi-Module benefits and why use it
  • How to handle dependencies or abstraction in multi-module
  • val vs const
  • inline keyword
  • lateinit vs lazy

Android Roadmap 2024

Topics Sub-Topics
Programming Languages
  • Kotlin
  • Java
  • Android Architecture image
    Runtime
  • Dalvik Virtual Machine
  • Android Runtime
  • Android Manifest
  • Package
  • Application Id
  • Permissions
  • Install-time Permissions
  • Special Permissions
  • Runtime Permissions
  • Permissions Groups
  • Android Build
  • APK
  • AAB
  • Thread
  • Processes
  • Threads
  • Inter Process Communication
  • Handlers
  • Loopers
  • Message Queue
  • UI Thread
  • Background Thread
  • Heap & Stack
  • Fundamental Components
  • Activity
  • Services
  • Broadcast Receiver
  • Content Provider
  • Intent
  • Implicit Intent
  • Explicit Intent
  • Intent Filters
  • Intent Flags
  • Activity
  • Activity Lifecycle
  • Tasks and Back Stacks
  • Bundles
  • Parcelables
  • Recent Screens
  • App Shortcuts
  • Context
  • Services
  • Service Lifecycle
  • Foreground Service
  • Background Service
  • Bound Service
  • AIDL
  • Job Scheduler
  • WorkManager
  • IntentService
  • Broadcast Receiver
  • Pub-Sub
  • System Broadcast
  • Permissions
  • Security
  • Content Provider
  • Content Resolver
  • Cursor
  • MIME Types
  • Contracts
  • Data Storage
  • App Specific Storage
  • Shared Storage
  • Preferences
  • Database
  • Scoped Storage
  • LRU Cache
  • SQLite
  • ROOM
  • Data Store
  • Fragments
  • Fragment Lifecycle
  • Dialog Fragment
  • Fragment Transactions
  • Fragment Manager
  • View Lifecycle
  • BackStack
  • Fragment-Activity Communication
  • Fragment-Fragment Communication
  • Navigation Component
  • Host
  • Graph
  • Controller
  • Back Stacks
  • Destinations
  • Deeplink
  • Jetpack Components
  • ViewModel
  • LiveData
  • Paging
  • Lifecycle
  • WorkManager
  • Data Binding
  • UI
  • XML
  • Jetpack Compose
  • Jetpack Compose
  • Composition
  • ReComposition
  • State Hoisting
  • Remember
  • RememberSaveable
  • Side Effects
  • LaunchedEffect
  • DisposableEffect
  • DerivedStateOf
  • SnapshotFlow
  • CompositionLocal
  • Theming
  • Modifier
  • Layouts
  • Box/Column/Row
  • Image/painter
  • Coil
  • LazyColumn/LayRow
  • Text/Button/ other ui components
  • Testing
  • UI Testing
  • Unit Testing
  • Espresso
  • Robolectric
  • Mockk
  • Debugging
  • Logcat
  • Timber
  • Break Points
  • Chucker
  • Charles
  • LeakCanary
  • Libraries
  • Retrofit
  • OkHttp
  • Glide
  • Material3
  • Hilt
  • Dagger
  • Retrofit
  • Benchmark
  • Micro Benchmark
  • Macro Benchmark
  • Static Analysis
  • Ktlint
  • Detekt
  • Android Lint
  • GitHub Actions
  • Pipeline
  • Build Generation
  • Workflow
  • Gradle
  • Commands
  • Groovy
  • Common Errors
  • ANR
  • App Crash
  • Fatal Error
  • OOM
  • ArrayOutOfBound
  • Proguard
  • Obfuscation
  • Keep
  • Code Architecture
  • MVP
  • MVVM
  • MVI
  • Modularization
  • Design Patterns
  • Network Layer
  • Data Layer
  • UI Layer
  • Domain/Repository/...
  • Firebase
  • Crashlytics
  • Remote Config
  • A/B Testing
  • App Release
  • App Release Process
  • App Distribution
  • Google Play Console
  • App Review/Ratings
  • App Size
  • App Policies

  • Kotlin Sheet 2024

    Jetpack Compose Sheet 2024

    Contributing Guidelines

    What interesting questions do you face while giving an interview for an Android Engineer role (any level)? Let's open a PR.

    If this Repository helps you, Show your ❤️ by buying me a ☕ below.

    Buy Me A Coffee

    If this repository helps you in any way, show your love :heart: by putting a :star: on this project :v: