我有一项服务,我想从中启动其他服务。我怎样才能做到这一点?这是来自developer.android.com的,它给了我NullPointerException。还有其他方法吗?
Intent intent = new Intent(this, HelloService.class);
startService(intent);
我发现只有这样的服务才能启动活动:
Intent i = new Intent();
i.setClass(this, MyActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
也许我需要使用此代码并以某种方式标记服务?
我在这里找到了解决方案:
https://groups.google.com/forum/#!topic/android-developers/LJkmfdy5SXE
在另一个应用程序中启动服务时,它可以使用完全限定的类名:
Intent i = new Intent();
i.setClassName("com.backgroundService", "com.backgroundService.MyService");
startService(i);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句