I have a Service
which is started from BroadcastReceiver
when a new incoming call arrives. In that Service
I start a new Thread
and do all the work there. What happens if the Main Activity
of my app is killed? I'm asking because I realised that in such a situation the Service
's startID
rises by one! Just like if the Service
's onStartCommand()
was called again or something like that. I'll give a short example:
Main Activity
is running somewhere in the background, incoming call arrives,Service
starts,stopSelf()
is called by the user action,Service
is destroyed.Main Activity
is running, incoming call arrives,Service
starts,Main Activity
is killed by clearing Recent apps list,stopSelf()
is called by the user action,Service
is NOT destroyed becausestartID
s don't match.Main Activity
is NOT running (killed by clearing Recent apps list), incoming call arrives,Service
starts,stopSelf()
is called by the user action,Service
is destroyed.
That is very strange, because startID
somehow changes its value when the Main Activity
is killed. I use START_NOT_STICKY
in my Service
's onStartCommand()
method so there is no way that Service
is recreated with a new startID
. Could someone explain this to me? What happens to the Service
or the separate Thread
where the service is running when Main Activity
is killed? Thanks in advance!