how to prevent service to run again if already running android

前端 未结 5 2267
猫巷女王i
猫巷女王i 2021-02-06 21:49

On click of a button I want to start service using method startService(new Intent(currentActivity.this,MyService.class)) but if service is running I don\'t want to

5条回答
  •  耶瑟儿~
    2021-02-06 22:26

    Use startService(). Start Service will call onStartCommand() If the Service isn't started yet it will Call onCreate(). Initialize your variables and/or start a Thread in onCreate().

提交回复
热议问题