Can I start a service using a shortcut?

I am trying to create a shortcut on the main screen, which when clicked starts the service instead of activity.

Is it possible? How?

Thanks!

+7
android
source share
2 answers

You can create a dummy activity that simply starts the Service and then ends:

public class MyServiceActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent(this, MyService.class); startService(intent); finish(); } } 
+9
source share

No, sorry. Shortcuts only trigger actions.

+5
source share

All Articles