Sticky service not restarting when created in custom object

前端 未结 1 1814
轻奢々
轻奢々 2021-01-22 06:02

I had a Singleton object that had a bound service. I wanted it to restart, and when I start my application from launcher, singleton object will initialize and bind to this exist

相关标签:
1条回答
  • 2021-01-22 07:03

    As you are returning START_STICKY this service will stop whenever you close/kill the app because after the App closed all the Reference/Value will become null for all Intent as well as variables and so STICKY service will not able to get Intent value. if you want to restart the service after app kills use return START_REDELIVER_INTENT

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return START_REDELIVER_INTENT;
    }
    

    this will restart the service in 5-10 seconds after app killed.

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