tags:

views:

34

answers:

1

I want to start a service that has parameters

public BackgroundHelperService(String name)

How can I do this using

Intent service = new Intent(cnx, BackgroundHelperService.class);

I cannot pass the name param.

+1  A: 

I cannot pass the name param.

Correct. You cannot pass constructor parameters. If BackgroundHelperService is extending IntentService, please supply a name yourself:

public BackgroundHelperService() {
  super("BackgroundHelperService");
}
CommonsWare
That worked, I noticed that if I do something like Toast.makeText(this, "Background Helper Service Created", Toast.LENGTH_LONG).show(); it will throw an exception because of the 'this' word. Do you know why this is? It seems that there is no Context for some reason.
jax
java.lang.NullPointerException
jax
@jax: I would not be surprised if you cannot create `Toasts` from services.
CommonsWare
@commonsWare but I have used Toasts in my other normal Services, ie not IntentSerivces
jax
I cant even get hold of the notification service. notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
jax
it seems if you do this in the onHandleIntent(Intent intent) it works, you just can't do it inside the constructor
jax
@jax: Never implement a constructor on an `Activity` or `Service`.
CommonsWare