0

I have a service that is supposed to collect data periodically. The service works just fine, as long as it is within the application's process. Since I want the service to stay up even after the application is closed, I set it to start on its own process, like so:

<service
    android:name=".services.BackgroundSensorService"
    android:exported="false"
    android:process=":BackgroundSens" >
    <intent-filter>
        <action android:name="android.intent.action.SEND" />
    </intent-filter>
</service>

When the service was not defined to run in a different process, it would start when calling StartIntent, and would receive all messages properly.

Now that it runs on a different process, it fails to start at all. I tried to set a break point in the OnStart method, but the code never gets there. Sending intents to the service never results in anything other than an ANR error (which would make sense if the service never started at all).

All I did was add the following line:

android:process=":BackgroundSens"

Am I doing something wrong?

Dan The Man
  • 1,835
  • 6
  • 30
  • 50
  • You should start service from your application class. See here: http://stackoverflow.com/a/34573169/4557274 – sembozdemir Jan 04 '16 at 14:05
  • you dont need `android:process` at all – pskink Jan 04 '16 at 14:18
  • @sembozdemir thanks for your reply. I am missing something here, if I have an activity that will start this service, how do I use the design in your given link? Should I create an App instance just so it runs my service? And if so, how do I bind to an already running service with this method? Should the user exit the application and start it again, I do not want to start another instance. I want to bind to the existing instance. – Dan The Man Jan 04 '16 at 14:30

0 Answers0