Hello I have an activity that binds to a service and registers some callback methods.
I would like for the activity to run for as long as the phone is on, the activity will bind register callbacks and unbind from time to time.
Also I've got a broadcast receiver that starts the service on boot and another that checks in regular times if the service is running and if not starts it.
My first problem is that only when the activity binds and start the service the service runs propertly, the code for starting that from the activity is as follows:
bindService(new Intent(IMonitorService.class.getName()),
Iconn, 0);
//start Monitor service.
Intent serviceIntent = new Intent(contxt,MonitorService.class);
contxt.startService(serviceIntent);
firstly,isn't it enough to just bind to the service? that ensures that the service will start if its not running right?
also the code for the broadcast receiver is this:
//start Monitor service.
Intent serviceIntent = new Intent(context,MonitorService.class);
context.startService(serviceIntent);
since I just want to start the service and let it run.
my manifest is:
for the receiver:
<receiver android:name=".BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
for the service :
<service android:name=".MonitorService"
android:process=":remote">
<intent-filter>
<!--
These are the interfaces supported by the service, which you can
bind to.
-->
<action android:name="sap.max.IMonitorService" />
<!--
This is an action code you can use to select the service without
explicitly supplying the implementation class.
-->
<action android:name="sap.max.AntiTheft.Monitor" />
</intent-filter>
</service>
Note that the service is running under its own process.
Using the above mentioned receiver the service is never run, it starts but it's onStart method is never called.
also for the alarm service in the main activity I do this :
Intent intent = new Intent(AntiTheft.this, LiveCheckerReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(this, 1234567, intent, 0);
and I've got this on my manifest:
<receiver android:name="LiveCheckerReceiver"
android:process=":remote" />
but this never works as well.
some final questions, if the service calls a callback method and the activity isn't bind it will throw a bind exception correct?
also how to test if my service is alive and running?
sorry for all those questions,regards maxsap