How to restart a Service after getting Killed by apps like “Advanced Task Killer”?

后端 未结 3 1950
刺人心
刺人心 2020-12-09 19:28

I have a public class that \'extends Service\' and this service is launched from an activity using startService(...). But after I use Advanced Task Killer, the service is ki

3条回答
  •  轮回少年
    2020-12-09 20:07

    If you want to restart your service automatically after being killed by another process, you can use following constants in your service,

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

    You can find more information on START_STICKY & START_NON_STICKY at,

    START_STICKY and START_NOT_STICKY

    Also please provide your code for more specific answer.

提交回复
热议问题