Is it possible to start a service with a shortcut?

匿名 (未验证) 提交于 2019-12-03 03:06:01

问题:

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!

回答1:

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();     } } 


回答2:

No, sorry. Shortcuts only launch activities.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!