2

I have an activity that gets some user input and puts that information as extra into an intent to start (create) a service.

I then want other apps to be able to use that service (bind to it).

I, however, do NOT want these apps to be able to start the service, as I, as mentioned before, need some user input to correctly start it. So if an app wants to use the service, it can only bind to it if it is running. If it isn't, the app can only start the activity that starts the service after getting user input.

As I understand it, setting android:exported in the manifest to true allows other apps BOTH binding and starting a service.

Is there any way to do what I need?

On another note: Is there any reason onCreate in a service does not get the intent? I would like to get the extra in onCreate, as I only need it when the service is first created. I'm currently circumventing this by getting it in onStartCommand and instantly returning if onStartCommand gets called a second time, but that seams like an unnecessary step.

BeneStr
  • 337
  • 2
  • 12
  • if your service is to store some info only and share it with other apps, consider a ContenProvider instead – pskink Sep 02 '14 at 06:44
  • @pskink No, the Server makes a connection to an external device over Bluetooth and after that connection is correctly established (which needs the user input) other apps can use the service to access specific features of that device. – BeneStr Sep 02 '14 at 06:59
  • ok, i dont understand why you dont want other apps to start it? if the service is once configured to properly start it can store that info and use it when other app wants to start it – pskink Sep 02 '14 at 07:16
  • @pskink Well, there are several things the Activity does. It makes sure the service is only started if Bluetooth is on (and if not asks the user to enable it), asks which device to connect to (there might be several and the user might choose to connect to a different one every time) and it makes sure the user get informed if there was an error and how to fix it (there is a lot that can go wrong when connecting). I or whoever writes the other apps would need to implement all that every time the service is needed. That's why I want one single Activity to control the service. – BeneStr Sep 02 '14 at 08:23
  • ok i see it now, but still don't know the problem you are facing, suppose the service was started by your config activity and other app starts it again, you check in onStartCommand that it is third party app and do nothing, if the service was not started and the third party app starts it you simple stopSelf() in onStartCommand – pskink Sep 02 '14 at 08:32

0 Answers0