Search code examples
androidservice

android service need to stop after sometime


I am running a Service using AlarmManager. The Service is running ok and I am stopping the Service manually (clicking a Button), but I need to stop the Service after sometime (it may be 10 seconds). I can use this.stopSelf();, but how do I call this.stopSelf(); after some given time?


Solution

  • May be you should consider using IntentService? It will be stopped when there is no work for it so you don't need to manage its state by yourself.