I have an activity and a service. When the Activity first starts up I
create an Intent for the service and call StartService(i). This properly
starts up the service triggering the services' onCreate event and
onStartCommand events.
Subsequent to that there are times when I want to pass the service some
information so, using the same Intent I add some data to a bundle using
i.putextra and call StartService(i) again. To my surprise the onCreate
event of the service executes again!! I would expect that only the
onStartCommand would execute on subsequent StartService(i) calls. The
service was indeed still running when the call was made.
Is my expectation correct? Why is onCreate executing again in the service?
//this is code from the Activity...
public void onCreate(Bundle savedInstanceState) {
.
.
.
i = new Intent(this, StalkService.class);
if (isMyServiceRunning())
{
i.putExtra("mode", "feedmethewholetrip");
this.startService(i);
}
else
{
i.putExtra("MESSENGER", messenger);
this.startService(i);
}
private boolean isMyServiceRunning() {
String sClassName;
ActivityManager manager = (ActivityManager)
getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service :
manager.getRunningServices(Integer.MAX_VALUE))
{
sClassName = service.service.getClassName();
Log.w(getClass().getName(), "Services are : " + sClassName);
if (sClassName.contains("com.deanblakely.StalkService")) {
return true;
}
}
return false;
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en