2012-12-08 3 views
0

"info"를 클릭하면 서비스 스타가 올바르게 작동하지만 노래를 시작/중지하는 서비스를 만들었지 만 멈출 수는 없습니다. 나는 "public void onClick"내에서 서비스를 중단하겠다는 의도를 넣어야하지만 오류가 있습니다.stopService inside public void onClick

이것은 서비스를 중지하는 코드입니다. 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(); 
+0

답장으로 익명의 클래스 객체 자체를 참조 할 수 있습니다 나 자신 : stopservice를 사용하여 새로운 메소드를 만들고 public void onClick을 호출하십시오. –

답변

1

stopService(new Intent(YourActivity.this, SobService.class)); 

를 액티비티 클래스 이름을 쓰기 대신에만 "this"의이 문장 만 "this"되지 활동 객체

+0

답장을 보내 주셔서 감사합니다! –

관련 문제