How to start a Service when .apk is Installed for the first time

后端 未结 10 1622
遇见更好的自我
遇见更好的自我 2020-11-22 10:33

In my Application I am not having any UI part, so I need to start a Service as soon as the Applicaton gets installed on the Device. I saw many links from which the answer wa

10条回答
  •  不思量自难忘°
    2020-11-22 11:10

    I agree with CommonsWare's answer to question: How to start android service on installation. In other words, you can't automatically start your service after you've just been installed.

    One more thing about newer Android platforms: if you don't have UI at all, you'll have trouble starting your service even when using BOOT_COMPLETE intent on Android 3.1+.

    That's because all installed applications are in stopped state. In this state applications will not receive ANY broadcast notifications.

    In order to activate your application some other application (or user) needs to start your service or activity, or content provider. The usual workflow is when user clicks on your application's icon.

    I've written a detailed explanations about this in my blog post.

提交回复
热议问题