0

曲を開始/停止するサービスを作成しました。「情報」をクリックすると、従軍星章が正しく表示されますが、停止できません。「publicvoidonClick」内でサービスを停止する意図を置く必要がありますが、エラーが発生しました。

これは、サービスを停止するコードです。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();
4

1 に答える 1

1

"this"このステートメントのみではなく、Activity クラス名を記述します。

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

"this"アクティビティ オブジェクトとしてではなく、匿名クラス オブジェクト自体を参照できるのは だけです。

于 2012-12-08T11:41:38.557 に答える