Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to start a service with a shortcut?

Tags:

android

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!

like image 469
gnobal Avatar asked Mar 08 '10 18:03

gnobal


People also ask

What is the shortcut for service?

Press the Win + R keys on your keyboard, to open the Run window. Then, type "services. msc" and hit Enter or press OK.

How do I enable a service from the command line?

Enable service Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to enable a service and press Enter: sc config "SERVICE-NAME" start=auto In the command, replace "SERVICE-NAME" for the name of the service that you want to enable.

What is the shortcut to open Control Panel?

The first method you can use to launch it is the run command. Press Windows key + R then type: control then hit Enter. Voila, the Control Panel is back; you can right-click on it, then click Pin to Taskbar for convenient access. Another way you can access the Control Panel is from within File Explorer.


2 Answers

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();
    }
}
like image 181
Dan Lew Avatar answered Dec 09 '22 14:12

Dan Lew


No, sorry. Shortcuts only launch activities.

like image 43
CommonsWare Avatar answered Dec 09 '22 14:12

CommonsWare