Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java AlertDialog.Builder中的Android stopService()_Java_Android_Android Intent_Android Activity_Android Service - Fatal编程技术网

Java AlertDialog.Builder中的Android stopService()

Java AlertDialog.Builder中的Android stopService(),java,android,android-intent,android-activity,android-service,Java,Android,Android Intent,Android Activity,Android Service,您好,我正在开发一个应用程序,我需要将我的stopService()放入其中;在AlertDialog.Builder的PositiveButton中,但我得到一个错误,我的代码是: 。。。。其他代码 .setPositiveButton("Yes",newDialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) {

您好,我正在开发一个应用程序,我需要将我的stopService()放入其中;在AlertDialog.Builder的PositiveButton中,但我得到一个错误,我的代码是:

。。。。其他代码

.setPositiveButton("Yes",newDialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,int id)
   {                                                                        

     finish();
     System.exit(0);                                    
     stopService(new Intent(this, Service.class));
  }
}
。。。。其他代码

尝试

.setPositiveButton("Yes",newDialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,int id)
   {                                                                        

     finish();
     System.exit(0);                                    
     stopService(new Intent(this, Service.class));
  }
}
public void onClick(DialogInterface dialog,int id)
   {                                                                        

       stopService(new Intent(<InsertYourActivityClassName>.this, Service.class));
       finish();                               

  }
public void onClick(DialogInterface对话框,int-id)
{                                                                        
stopService(新意图(.this,Service.class));
完成();
}
试试看

public void onClick(DialogInterface对话框,int-id)
{                                                                        
stopService(新意图(.this,Service.class));
完成();
}

欢迎来到SO。请仔细阅读本网站的张贴规则。另外,请发布此问题的日志,并提供尽可能多的错误信息,否则您的问题将被拒绝。您应该删除此
系统。退出(0)
。欢迎使用SO。请仔细阅读本网站的张贴规则。另外,请发布此问题的日志,并提供尽可能多的错误信息,否则您的问题将被拒绝。您应该删除此
系统。退出(0)
。编辑,将
更改为
。此
编辑,将
更改为
。此