tags:

views:

63

answers:

3

I'm trying to create a shortcut on the home screen that, when pressed, will start a service instead of an activity.

Is it possible? How?

Thanks!

+3  A: 

No, sorry. Shortcuts only launch activities.

CommonsWare
+2  A: 

You can create a dummy Activity that simply starts a Service, then finishes itself:

public class MyServiceActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(this, MyService.class);
        startService(intent);
        finish();
    }
}
Daniel Lew
True. I was taking him literally, but that would certainly work. You might have to play with the theme a bit, though, so you don't get a momentary flash of an activity.
CommonsWare
This code definitely works and this is what my code currently does. I was trying to skip the extra activity step.
gnobal
Be sure your users understand what's going on, though. I can see this sort of thing garnering a lot of one-star, "tapped the shorcut and nothing happened" complaints on the Market.
CommonsWare
That's a good idea. Thanks
gnobal
A: 

What is the service doing? What about just setting up a receiver to listen to something the service uses to launch it instead?

arc