问题描述
我们可以在Android的服务的多个实例?我想它可以使在一个特定的时间电话沉默了服务,我想重新使用该服务,使手机在特定的时间振动模式。所以基本上,如果我可以让服务运行多次,那么就没有必要建立另一个服务在振动模式设定手机。此外,如果我们可以同时运行多个实例,那么请你解释一下如何阻止它。任何code暗示将有很大的帮助。
没有。你可以有服务
的多个子类,但服务
的任何给定的子类将有precisely 0或1实例在任何给定的时刻。
您不应该使用服务的任何。使用 AlarmManager
和的BroadcastReceiver
,请
Can we have multiple instance of a Service in Android ? I want a service which can make phone silent on a specific time and I want to re use that service to make the phone in vibrate mode in specific time. So basically if I can make the service run multiple times then there is no need to create another service to set phone in vibrate mode. Also if we can run multiple instance then please explain how to stop it. Any code hint will help a lot.
No. You can have multiple subclasses of Service
, but any given subclass of Service
will have precisely 0 or 1 instances at any given moment.
You should not be using a service for any of that. Use AlarmManager
and a BroadcastReceiver
, please.
这篇关于如何让服务在Android的多实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!