一 Service启动绑定方式
AndroidManifest.xml Service注册的代码
<service android:name="com.example.service.MyService">
<intent-filter>
<action android:name="com.example.service.IMyService" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
1.am启动
am startservice -n com.example.service/com.example.service.MyServic
或者根据action启动
am startservice -a com.example.service.IMyService
2.代码启动
Intent intent = new Intent(this,Myservice.class);
startService (intent);
3.绑定服务
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example.service",
"com.example.service.MyService"));
context.bindService(myIntent, mConnection,BIND_AUTO_CREATE);