Is it possible to start a service without starting an activity? My plan is to write an application which shows a notification when Bluetooth device is connected and a headset Thanks for answers
Asked
Active
Viewed 139 times
-2
-
What have you tried? What issues did you encounter? – Okas May 19 '18 at 17:12
-
Nothing I don't know how to do it – Philxw May 19 '18 at 17:13
-
Possible duplicate of https://stackoverflow.com/questions/10909683/launch-android-application-without-main-activity-and-start-service-on-launching – Ghulam Moinul Quadir May 19 '18 at 17:16
1 Answers
-1
Services ONLY can be started from Android components , such as Activity
, BroadcastReceiver
and either from another service
. Anyway to start a service you need a Context
, Because you're gonna call Context.startService(i)
.
In your case I suggest you to start your service from a BroadcastReceiver
as same as this one :
How to detect when a user plugs headset on android device? (Opposite of ACTION_AUDIO_BECOMING_NOISY)

AmirHmZ
- 9
- 5