tags:

views:

459

answers:

1

I have a device management application, which essentially runs as a service in the background from boot. I'd like to start this application immediately after installation. How do I achieve this?

+3  A: 

You cannot do this -- there is no way to automatically start your service merely because it was installed.

The application must first be invoked by the user through some sort of activity. Or, you are going to need to hook into some relevant broadcast Intent via the manifest, so you can get control when one of those events occur and kick off your service that way. Or, you are going to need to ask the user to reboot so your BOOT_COMPLETED Intent filter can get control.

CommonsWare
Thanks, I suspected this might be the case. Seems like a bit of an oversight given how well thought out the OS is generally.
Rob Charlton
It's a security thing, as far as I understand it. It is definitely not an oversight, as the core Android team has commented on this request several times in the past.
CommonsWare
Yes, it is deliberate. Application installation happens automatically in the background when the app is downloaded. We prefer that no app code run until the user explicitly goes to the app the first time. (And please please do not tell the user to reboot their device. There is no need for that. Just let them run your app and do your initialization when first run.)
hackbod
Ok, so it isn't really for security since I can run code on boot, or on an incoming SMS, or on the _next_ package install. I would classify this more in the category of a "nudge" towards expected platform behaviour.To my customers though, it just looks like a bug - on Android there is an extra hoop to jump through to get the service running. This is not an application that a user would select from the Market, this is more likely the kind of application that an operator or enterprise would want to install on the handset, preferably without any end user interaction at all.
Rob Charlton
If an operator is installing it on the handset, the phone will be rebooted before it gets to the user, simply because operators don't keep their inventory of phones running -- they'll be shut off after customization and before delivery to a customer. With respect to the enterprise, Android's present form is designed for consumers, and so there will be various things in the platform that will run counter to what an enterprise will want, in the interests of protecting consumers from malware.
CommonsWare