我创建了一个服务来启动/停止一首歌曲,现在当我点击“信息”时,服务星号正确,但我无法停止它。我应该打算在“public void onClick”中停止服务,但我有一个错误。
this,是停止服务的代码: stopService(new Intent(this, SobService.class));
private void Info(){
startService(new Intent(this, SobService.class));
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.info, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(view).create();
TextView text=(TextView) findViewById(R.id.infoView1);
builder.setCancelable(false);
builder.setPositiveButton("Chiudi", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id) {
//stopService(new Intent(this, SobService.class));
dialog.cancel();
}
});
builder.show();