Stop All Started Services on App Close / Exit

后端 未结 2 418
旧巷少年郎
旧巷少年郎 2020-12-28 23:49

Is it possible to stop all started services when the user hits the Home Button?

I use:

startService(new Intent(ClassName.this, Class         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-29 00:20

    If you want services to stop when the user leaves your app, I would ask if you want to use services at all. You may just be making your application way more complicated than it needs to be.

    Also, this line is really questionable:

    startService(new Intent(ClassName.this, ClassName2.class));
    

    You are making an Intent whose action is the class name of one class, and data URI is the class name of another class...! Maybe you mean something like "new Intent(context, MyService.class)"?

提交回复
热议问题