how to keep an Intent service running

后端 未结 3 1301
忘了有多久
忘了有多久 2020-12-30 10:58

I have two examples of Intentservice. One is the Download example in the commonsware book. the other is at http://www.vogella.com/articles/AndroidServices/article.html#ser

3条回答
  •  梦毁少年i
    2020-12-30 11:24

    To keep a service running, your service need to return START_STICKY in the service method onStartCommand().

    With this, the service will be running even if you exit form your activity.

    Note: The Android still kills services after some time (30 mintus to 1 hour) if they are not foreground services. Use startForeground(notification) to make it foreground.

    good luck

提交回复
热议问题