I’ll explain Android Services like a tutorial: first meaning and lifecycle, then Started/Foreground/Bound services, pseudocode, Kotlin examples, and scenario-based interview cases.

Common Mistakes

Mistake 1: Doing Heavy Work on Main Thread

Wrong Code

override fun onStartCommand(
    intent: Intent?,
    flags: Int,
    startId: Int
): Int {

    uploadLargeFile()

    return START_NOT_STICKY
}

Correct Code

override fun onStartCommand(
    intent: Intent?,
    flags: Int,
    startId: Int
): Int {

    Thread {
        uploadLargeFile()
        stopSelf(startId)
    }.start()

    return START_NOT_STICKY
}


Mistake 2: Starting Background Service from Background App

Modern Android restricts background execution.

Better Approach

Use WorkManager for deferrable background tasks.
Use Foreground Service only for visible urgent tasks.


Mistake 3: Foreground Service Without Notification

Wrong

Start foreground service without showing notification

Correct

Create notification
Call startForeground()
Then start actual work


Mistake 4: Forgetting to Stop Service

Wrong

Upload completed but service is still running

Correct

stopSelf()


Mistake 5: Forgetting to Unbind Bound Service

Wrong

Activity destroyed but service is still connected

Correct

if (isBound) {
    unbindService(connection)
    isBound = false
}


Interview Questions and Answers

Q1. What is a Service?

A Service is an Android component used to perform work without a UI.

It can be:

Started Service
Foreground Service
Bound Service


Q2. Does Service run on background thread?

No.

A Service runs on the main thread by default.

For heavy work, use:
Thread
Coroutine
Executor
WorkManager


Q3. What is Foreground Service?

A Foreground Service performs user-visible ongoing work and must show a notification.

Examples:

Music
Navigation
Fitness tracking
Ongoing call
Location tracking


Q4. What is Bound Service?

A Bound Service allows Activity or another component to connect with Service and call its methods.

Example:

Activity controls music service using play/pause methods.


Q5. Difference Between Started and Bound Service

PointStarted ServiceBound Service
Started bystartService()bindService()
CommunicationOne-wayTwo-way
Activity calls methods?NoYes
Stops whenstopSelf() / stopService()All clients unbind
ExampleUpload fileMusic controller


Q6. What happens if Service is killed?

It depends on onStartCommand() return value.

Return TypeResult
START_NOT_STICKYDo not restart
START_STICKYRestart, but intent may be null
START_REDELIVER_INTENTRestart with old intent


Q7. Should we use Service for periodic background sync?

Usually no.

Use:

WorkManager

because it handles:

Battery optimization
Network constraint
Retry
Background restrictions


Q8. Can one Service be both Started and Bound?

Yes.

Example:

Music Service

startService()
    -> Keeps music running

bindService()
    -> Allows Activity to control music


 Final Memory Trick

Started Service
    = Do this work

Foreground Service
    = Do this work and show notification

Bound Service
    = Let me connect and talk to you

WorkManager
    = Do this work later/reliably


Final Short Summary

ConceptMeaning
Android ServiceWork without UI
Started ServiceOne-way independent work
Foreground ServiceUser-visible long-running work
Bound ServiceTwo-way communication with Activity
WorkManagerReliable deferrable background work

Best Practice

Use Foreground Service only for active user-visible tasks.

Use WorkManager for deferrable background tasks.

Use Bound Service when Activity needs direct communication.

Never do heavy work directly on main thread inside Service.

Always stop or unbind Service properly.