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.
Absolutely Correct. Only one instance of Service is created for an application process. And when you call StartService(); again, then only onStartCommand() gets called and new Intent is passed to onStartCommand() method. Note: onCreate() is not called again.
Go to: File -> Settings -> Appearance & Behavior -> System Settings -> Project Opening. Check [x] "Confirm window to open project in". Now open the other (2nd) project with File -> Open... etc. You will now be asked if you want to open a new window or replace what you already have.
An instance is a single occurrence of an event including time zone specific start and end days and minutes. The instances table is not writable and only provides a way to query event occurrences.
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.
I do not think the service can be used for a such purpose. Service has to provide some functionality, but only one meaning, not for several different purposes. It's better to create additional service for that to keep code simple and clear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With