如何让服务在Android的多实例 [英] How to have multiple instance of Service in Android

查看:121
本文介绍了如何让服务在Android的多实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在Android的服务的多个实例?我想它可以使在一个特定的时间电话沉默了服务,我想重新使用该服务,使手机在特定的时间振动模式。所以基本上,如果我可以让服务运行多次,那么就没有必要建立另一个服务在振动模式设定手机。此外,如果我们可以同时运行多个实例,那么请你解释一下如何阻止它。任何code暗示将有很大的帮助。

解决方案
  

我们可以在Android的服务的多个实例?

没有。你可以有服务的多个子类,但服务的任何给定的子类将有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.

解决方案

Can we have multiple instance of a Service in Android ?

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.

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.

You should not be using a service for any of that. Use AlarmManager and a BroadcastReceiver, please.

这篇关于如何让服务在Android的多实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆