views:

221

answers:

2
  1. Activity 1 starts a Service, using the standard Intent.
  2. Activity 1 starts Activity 2. Then, Activity 1 gets finished().
  3. Now, there's only Activity 2.

How does Activity 2 kill the Service, since that Intent was generated in Activity 1? I don't want to pass the Intent everywhere...

+1  A: 

You shouldn't care about these things. Just call stopService and pass it a new Intent object.

Nikola Smiljanić
+1  A: 

Hello, Generally there are several different ways to start service:

  1. startService() - after that you need to explicitly stop service with stopService()
  2. [bindService()][2] - this method allow you to manage the lifecycle of service automaticaly. So you can make service to stop after the last client said unbind();

For details check docs

[2]: http://developer.android.com/reference/android/content/Context.html#bindService(android.content.Intent, android.content.ServiceConnection, int)

ponkin