views:

88

answers:

1

I know you can start a service on Boot, but how do I start the service after the app has been installed or reinstalled?

I would like to start the service once the app is put on device by Debug/Run of Eclipse.

+1  A: 

but how do I start the service after the app has been installed or reinstalled?

You do not get control after an install, so you have to start the service through your activity or something.

There's an ACTION_PACKAGE_REPLACED broadcast Intent you can monitor for the reinstall scenario, though I have not tried it.

CommonsWare
@CommonsWare So I have to start the Service when my main activity is started. That's fine. Now, if the service is running, and if I start it again (when my main activity starts to ensure it started) eventually will fire the start method twice. How do I detect in service if it has been already started and received a second start?
Pentium10
"Now, if the service is running" -- it isn't running, since you reinstalled the app. "How do I detect in service if it has been already started and received a second start?" -- `boolean` data member would seem to be one possibility, toggled in the service's `onStart()`. You should also be able to use `getRunningServices()` in `ActivityManager` to have the activity only do the manual start if needed, though I have not tried this. You will only run into your problem with an everlasting service (one that tries to run on boot and forever), and I'm not a fan of those.
CommonsWare