Android Background Service is restarting when application is killed

前端 未结 7 2250
逝去的感伤
逝去的感伤 2020-11-27 17:20

I am developing an application in which a background service is created to collect sensor data. I am starting the service from my activity:

startService(new          


        
7条回答
  •  渐次进展
    2020-11-27 17:42

    I know its much late to answer this question, but may be it can be helpful to others. This really helped me for my Music Player App.

    If there are services which can be disruptive or can affect the user experience like music etc , then in that case you have to use Notification and when service is started successfully, then create the Notification and use the function

    startForeground(int Notification_id,Notification);
    

    This will run your service in background without restarting and reinvoking its methods

    https://developer.android.com/reference/android/app/Service.html

提交回复
热议问题