问题描述:

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?

网友答案:

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.

网友答案:

There was a hole - the Android Analytics SDK used to send an intent right after installation - but that got closed (producing lots of confusion, of course).

But the final answer, I believe, is here:

http://developer.android.com/about/versions/android-3.1.html#launchcontrols

This seems to suggest that, as of 3.1, Google made the decision that apps are in a stopped state until the user explicitly activates them, e.g. by launching app or placing widget.

This means that the strategy of listening of a common broadcast (i.e. to get your app launched surreptitiously) won't work either.

相关阅读:
Top