Android Interview Questions and Answers (Complete Guide)-Part-1
Section 1: Android Basics (Fresher Level)
1. What is Android?
Answer:
Android is an open-source mobile operating system developed by Google based on the Linux kernel.
Features:
- Open source
- Multi-touch support
- Rich application framework
- Supports Java and Kotlin
- Large ecosystem
2. What are the main components of Android?
Answer:
Android has four major application components:
- Activity
- Service
- Broadcast Receiver
- Content Provider
Example:
class MainActivity : AppCompatActivity()
Activity represents a single screen.
3. What is an Activity?
Answer:
An Activity represents a user interface screen.
Example:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
4. Explain Activity Lifecycle.
Answer:
Lifecycle methods:
onCreate()
onStart()
onResume()
onPause()
onStop()
onDestroy()
Lifecycle flow:
onCreate
↓
onStart
↓
onResume
↓
Running
↓
onPause
↓
onStop
↓
onDestroy
5. Difference between onStart() and onResume()
| onStart() | onResume() |
|---|---|
| Activity visible | Activity interactive |
| Called before resume | Called after start |
| UI visible | User can interact |
6. What is Intent?
Answer:
Intent is used for communication between Android components.
Example:
val intent = Intent(this, SecondActivity::class.java)
startActivity(intent)
7. Types of Intents
Explicit Intent
Intent(this, DetailsActivity::class.java)
Implicit Intent
Intent(Intent.ACTION_VIEW)
8. What is AndroidManifest.xml?
Answer:
It contains:
- Activities
- Services
- Permissions
- Broadcast Receivers
- Application metadata
Example:
<uses-permission android:name="android.permission.INTERNET"/>
9. What is Context?
Answer:
Context provides access to:
- Resources
- System services
- Application environment
Example:
Toast.makeText(this, "Hello", Toast.LENGTH_SHORT).show()
10. Difference between Application Context and Activity Context
| Application Context | Activity Context |
|---|---|
| App lifecycle | Activity lifecycle |
| Singleton usage | UI-related operations |
| No theme access | Theme access |
Section 2: Android Components
11. What is a Service?
Answer:
Service performs background operations.
Example:
class MusicService : Service()
Types:
- Foreground Service
- Background Service
- Bound Service
12. What is Broadcast Receiver?
Answer:
Receives system-wide events.
Example:
class BatteryReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
}
}
13. What is Content Provider?
Answer:
Used to share data between applications.
Example:
contentResolver.query(...)
14. What is Fragment?
Answer:
Reusable UI component hosted inside an Activity.
Example:
class HomeFragment : Fragment()
15. Fragment Lifecycle
onAttach()
onCreate()
onCreateView()
onViewCreated()
onStart()
onResume()
onPause()
onStop()
onDestroyView()
onDestroy()
Section 3: Kotlin Interview Questions
16. Why Kotlin over Java?
Answer:
Advantages:
- Null safety
- Coroutines
- Less boilerplate
- Extension functions
- Data classes
17. What is a Data Class?
data class User(
val id: Int,
val name: String
)
Automatically generates:
- equals()
- hashCode()
- copy()
- toString()
18. What is Null Safety?
var name: String? = null
Safe call:
name?.length
Elvis operator:
val length = name?.length ?: 0
19. What are Extension Functions?
fun String.greet() {
println("Hello $this")
}
Usage:
"Android".greet()
20. What are Higher Order Functions?
fun execute(action: () -> Unit) {
action()
}
Usage:
execute {
println("Running")
}
Section 4: Jetpack Compose
21. What is Jetpack Compose?
Answer:
Modern declarative UI toolkit for Android.
Example:
@Composable
fun Greeting() {
Text("Hello Android")
}
22. Difference between XML and Compose
| XML | Compose |
|---|---|
| Imperative | Declarative |
| More boilerplate | Less code |
| Separate files | Single language |
23. What is @Composable?
Answer:
Marks a function that describes UI.
@Composable
fun HomeScreen()
24. What is State in Compose?
var count by remember {
mutableStateOf(0)
}
State changes trigger recomposition.
25. What is Recomposition?
Answer:
Compose redraws affected UI when state changes.
Section 5: MVVM Architecture
26. What is MVVM?
Layers:
View
↓
ViewModel
↓
Repository
↓
Data Source
Benefits:
- Separation of concerns
- Testability
- Maintainability
27. What is ViewModel?
class HomeViewModel : ViewModel()
Stores UI state.
Survives configuration changes.
28. What is LiveData?
val users = MutableLiveData<List<User>>()
Lifecycle-aware observable.
29. LiveData vs StateFlow
| LiveData | StateFlow |
|---|---|
| Android specific | Kotlin |
| Lifecycle aware | Coroutine based |
| Legacy | Modern |
30. What is Repository Pattern?
Single source of truth for data.
class UserRepository
Handles:
- API
- Database
- Cache
Section 6: Coroutines
31. What is Coroutine?
Lightweight thread.
viewModelScope.launch {
fetchUsers()
}
32. launch vs async
launch
launch { }
Returns Job.
async
async { }
Returns Deferred.
33. What is Dispatcher?
Dispatchers.Main
Dispatchers.IO
Dispatchers.Default
34. What is suspend function?
suspend fun getUsers()
Can pause and resume execution.
35. What is Structured Concurrency?
Child coroutines are tied to parent lifecycle.
Section 7: Flow
36. What is Flow?
flow {
emit(1)
}
Asynchronous data stream.
37. StateFlow vs SharedFlow
| StateFlow | SharedFlow |
|---|---|
| State holder | Event stream |
| Latest value | Multiple values |
38. Flow Operators
map()
filter()
debounce()
combine()
zip()
Section 8: Dependency Injection
39. What is Dependency Injection?
Providing dependencies from outside.
Benefits:
- Testability
- Scalability
- Decoupling
40. Hilt vs Dagger
| Hilt | Dagger |
|---|---|
| Easier | Complex |
| Google recommended | More control |
41. Hilt Setup
@HiltAndroidApp
class MyApp : Application()
42. Constructor Injection
class UserRepository @Inject constructor(
private val api: ApiService
)
Section 9: Networking
43. What is Retrofit?
Popular HTTP client.
@GET("users")
suspend fun getUsers()
44. Retrofit vs Volley
| Retrofit | Volley |
|---|---|
| REST APIs | Simple requests |
| Serialization support | Limited |
45. What is OkHttp?
Network layer used by Retrofit.
46. What is Interceptor?
class AuthInterceptor : Interceptor
Used for:
- Logging
- Authentication
- Headers
47. Difference between PUT and PATCH
| PUT | PATCH |
|---|---|
| Full update | Partial update |
48. How do you handle API errors?
try {
} catch (e: Exception) {
}
Use:
- Error models
- Result wrappers
- Sealed classes
Section 10: Room Database
49. What is Room?
Jetpack ORM for SQLite.
50. Room Components
@Entity
@Dao
@Database
Example:
@Entity
data class User(
@PrimaryKey val id:Int
)
Section 11: Android Testing
51. Unit Testing
@Test
fun loginSuccess()
52. Mockito
whenever(repo.getUsers())
53. MockK
Popular Kotlin mocking framework.
54. Espresso
UI Testing framework.
onView(withId(R.id.button))
To be continue on next part