Running a Service forever in background - Android

后端 未结 4 466
青春惊慌失措
青春惊慌失措 2021-01-15 11:50

I have created a Service in my android application which starts automatically on BOOT_COMPLETE through BroadcastReceiver. And That is

相关标签:
4条回答
  • 2021-01-15 11:57

    It is very simple.
    steps:
    1.create a Service class.
    2.create a BroadcastReceiver class
    3.call BroadReceiver in onDestroy method of service
    4.In onReceive method of BroadReceiver class start service once again.
    refer this link

    0 讨论(0)
  • 2021-01-15 12:05

    According to Service documentation

    The service will at this point continue running until Context.stopService() or stopSelf() is called.

    So your service will run forever until system will not decide to kill it because of lack of resources.

    0 讨论(0)
  • 2021-01-15 12:08

    According to documentation.

    Reasons your service is killed:

    The Android system stops a service only when memory is low and it must recover system resources for the activity that has user focus.

    So as long as the above condition isn't met, your service will run forever.

    0 讨论(0)
  • 2021-01-15 12:12

    Write your handler code in onStartCommand. But remember, your service will be paused when device goes in "sleep mode".

    0 讨论(0)
提交回复
热议问题