开发者

How to start android service on installation

I have a device management application, which essenti开发者_运维知识库ally 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜