java - AlertDialog.Builder 中的 Android stopService()

标签 java android android-intent android-activity android-service

您好,我正在开发一个应用程序,我需要将我的 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));
  }
}

....其他代码

最佳答案

尝试

public void onClick(DialogInterface dialog,int id)
   {                                                                        

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

  }

关于java - AlertDialog.Builder 中的 Android stopService(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17390959/

相关文章:

java - 在 EJB 中使用 @Timeout 代替 Thread.sleep()

java - 许多 jar 库版本兼容性

android - onHandleIntent 没有被调用

android - 如何在 android 中打开 Facebook 和 Twitter

java - 我可以对不同的 Tomcat 实例进行 URL 重写吗?

android - Gradle:错误:非法的 unicode 转义

android - 连续报告用户位置的最佳实践

Android 屏幕旋转,ACCELEROMETER_ROTATION

android - 使用我的 Android 应用程序将文本标签发送到 Instagram

java - 方法重载时复制方法