0
我想启动服务使用活动。具体来说,它是IntentService。但我有两个问题:启动服务使用活动
当开始我的代码
private void switchService(boolean isEnable, String serviceName){
Intent intent = new Intent();
intent.setClassName(TestPhoneServiceActivity.this, serviceName);
if(isEnable){
startService(intent);
}
else{
if(isServiceRunning(serviceName)){
stopService(intent);
while(isServiceRunning(serviceName)){
}
Toast.makeText(this, "Service stopped Successfully!", Toast.LENGTH_LONG).show();
}
}
}
DDMS有错误:Unable to start service Intent { cmp=com.xx.android/.AndroidPhoneService }: not found
但道路是正确的。那么问题是什么呢?我也想调用一个系统服务。我应该把它写入配置文件吗?
然后我启动IntentService使用intent.setClass。
ActivityManager manager = (ActivityManager)getSystemService(ACTIVITY_SERVICE)
我找不到这个服务对象。 IntentService是否自动完成并销毁?IntentService的生命周期与其他Service不同?
你是否在清单文件中添加了你的服务? –
不停止intentservice,它在完成时自行停止 – njzk2
发布您描述服务的清单部分 – njzk2