Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.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
Android 如何停止活动中的服务_Android_Android Service_Alarmmanager - Fatal编程技术网

Android 如何停止活动中的服务

Android 如何停止活动中的服务,android,android-service,alarmmanager,Android,Android Service,Alarmmanager,我是服务新手,无法找到停止由alarm manager启动的服务的方法 这是停止服务的代码: stopservices() { CancelAlarm(getApplicationContext()); Intent intent1 = new Intent(this, CrService.class); stopService(intent1); } // method Cancel alarm public void C

我是服务新手,无法找到停止由alarm manager启动的服务的方法

这是停止服务的代码:

    stopservices()
    {
    CancelAlarm(getApplicationContext());
    Intent intent1 = new Intent(this, CrService.class);        
    stopService(intent1);
     }

 // method Cancel alarm
 public void CancelAlarm(Context context)
    {
        Intent intent = new Intent(context, ReceiverPositioningAlarm.class);
        PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
        AlarmManager AvdhiCralarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        AvdhiCralarm.cancel(sender);
        sender.cancel();
       // stopService(new Intent(this, CrService.class));
    }

请尝试将此更改为yourclassname。this,yourclassname您调用服务的类的名称让我知道这是否适用于您,或者如果您有更多代码和错误堆栈,请支持更多代码和错误堆栈
stopservices()
    {
    CancelAlarm(getApplicationContext());

     }

 // method Cancel alarm
 public void CancelAlarm(Context context)
    {
        Intent intent = new Intent(context, ReceiverPositioningAlarm.class);
        PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
        AlarmManager AvdhiCralarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        AvdhiCralarm.cancel(sender);
        sender.cancel();
     // just write your context before call stop service & your name class before this
       context.stopService(new Intent(Yourcalss.this, CrService.class));
        ^                                ^
        |--------------------------------|
    }