//定义Intent通过给定的ACTION来启动服务
Intent intent=new Intent();
intent.setAction(MyService.ACTION);
startService(intent);
//service的部分代码
public class MyService extends Service {
public static final String ACTION = "com.example.codetest_1.action.startPlayService";
//清单文件
<service
android:name=".MyService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.example.codetest_1.action.startPlayService" />
</intent-filter>
</service>
我实在看不出什么问题了= =一点按钮程序就结束
I/Process: Sending signal. PID: 17843 SIG: 9
Application terminated.
貌似是5.0以后不允许隐式启动Service,试一下:
Intent mIntent = new Intent();
mIntent.setAction(XXX.XXX.XXX);
mIntent.setPackage(pkgName);//应用的包名
context.startService(mIntent);