1

After doing some study, I summary few points as below, please let me know if i am wrong.

An activity start a service by "onStartCommand", In the service class. onStartCommand() {

return START_NOT_STICKY;

} So, with the START_NOT_STICKY, the service will run forever unless being killed by system memory low.

The activity associated withe the service will be get killed more easily, leaving the service alone.

Below is no so sure: I could add an icon in task bar and a notification block in notification page. I can add onchecklistener on them. And when the icon is clicked, I have to check if the activity is being killed by broadcasting, and restart the activity and update the view.

manhon
  • 683
  • 7
  • 27

1 Answers1

1

An activity start a service by "onStartCommand"

Activity doesn't start a service by calling onStartCommand but either calling startService() or bindService(), accordingly system calls either onStartCommand or onBind.

With the START_NOT_STICKY, the service will run forever unless being killed by system memory low.

Service is meant for performing long operations in background without any user interface. Integer you return in onStartCommand method of your service decides action system should perform if your service is killed.

The activity associated with the service will be get killed more easily, leaving the service alone.

Service has no user interface. Service will keep running depends on if you started service by calling bindService() or startService()

I could add an icon in task bar and a notification block in notification page.

Yes you can add notification to notification bar.

I can add onchecklistener on them.

You can define and set Pending Intent on the notification

And when the icon is clicked, I have to check if the activity is being killed by broadcasting, and restart the activity and update the view.

Read this, Starting Activity through notification: Avoiding duplicate activities

Community
  • 1
  • 1
Anirudh
  • 389
  • 1
  • 7