- 一、Service没触发原因
- 二、解决步骤
- 1.手动注册
- 2.在MainActivity当添加代码
引入service服务AS不会自动生成相关配置,需要到AndroidMainfest.xml里手动注册
二、解决步骤 1.手动注册代码如下:
2.在MainActivity当添加代码
//初始化函数
private Intent mIntentService;
protected void onCreate() {
super.onCreate(savedInstanceState);
starNetService()
}
private void startNetService() {
mIntentService= new Intent(this, NetService.class);
startService(mIntentService);
}
//停止函数
@Override
protected void onDestroy() {
super.onDestroy()
stopNetService();
}
private void stopNetService() {
if (mIntentService== null) return;
stopService(mIntentService);
mIntentService= null
}



