如何在Android中拥有多个Service实例 [英] How to have multiple instance of Service in Android

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

问题描述

我们可以在 Android 中拥有多个服务实例吗?我想要一项可以让手机在特定时间静音的服务,我想重新使用该服务使手机在特定时间处于振动模式.所以基本上如果我可以让服务多次运行,那么就不需要创建另一个服务来将手机设置为振动模式.另外,如果我们可以运行多个实例,那么请解释如何停止它.任何代码提示都会有很大帮助.

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.

推荐答案

我们可以在 Android 中拥有多个服务实例吗?

Can we have multiple instance of a Service in Android ?

没有.你可以有多个 Service 的子类,但是任何给定的 Service 子类在任何给定时刻都会有 0 或 1 个实例.

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.

您不应为此使用任何服务.请使用 AlarmManagerBroadcastReceiver.

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

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

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